I\'m trying to use the native Fetch and FormData APIs to upload multiple files at once to the server but I can\'t for the life of me get it to work. Here\'s what I\'ve got:
The solution was to change files
to files[]
:
// acceptedFiles are File objects coming from `react-dropzone`.
function handleSubmit(acceptedFiles) {
const data = new FormData();
for (const file of acceptedFiles) {
data.append('files[]', file, file.name);
}
return fetch('https://example.com/api/upload', {
method: 'POST',
body: data,
});
}