const handleFileUpload = async (event) => {
const formData = new FormData(event.currentTarget)
event.currentTarget.reset()
const { data } = await fetch(`${import.meta.env.VITE_SERVER_URL}/upload`, {
method: 'POST',
credentials: 'include',
body: formData,
}).then((res) => res.json())
}
...
<form onSubmit={handleFileUpload}>
<input type="file" name="file" required />
<button type="submit" disabled={loading}>
Upload
</button>
</form>
const handleFileUpload = async (event) => {
const formData = new FormData(event.currentTarget)
event.currentTarget.reset()
const { data } = await fetch(`${import.meta.env.VITE_SERVER_URL}/upload`, {
method: 'POST',
credentials: 'include',
body: formData,
}).then((res) => res.json())
}
...
<form onSubmit={handleFileUpload}>
<input type="file" name="file" required />
<button type="submit" disabled={loading}>
Upload
</button>
</form>