```

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Index</title>
</head>

<body>
    <form id="formElem">
        <!-- <input type="text" name="firstName" value="John"> -->
        <input type="file" name="picture" accept="image/*">
        <input type="submit">
    </form>
    <script>
    	const formElem = document.getElementById('formElem')
	    formElem.onsubmit = async (e) => {
	        e.preventDefault();
	        let response = await fetch('/v1/upload', {
	            method: 'POST',
	            body: new FormData(formElem)
	        });

	        let result = await response.text();

	        alert(result);
	    };
    </script>
<!-- source: https://javascript.info/formdata -->
</body>

</html>
2021-11-16  ·  3 次查看  ·  V2EX