Morning,
I want to understand why my formData isn’t appending the files. I am currently checking the formData with console.log(formData.entries()
and it is coming back empty. This is the same when trying to process it on the backend.
Below is the code that I am using and the console information I am receiving. The file information is in the variables, I just don’t understand why it’s not appending.
useEffect(() => {
async function handleMultipleSubmit(event) {
const formData = new FormData();
console.log(files);
files.forEach((file, index) => {
console.log(file);
formData.append(`file${index}`, file);
});
console.log(formData.entries());
await axios
.post("/api/farmers/csv", formData)
.then((response) => {
if (response.data.success) {
console.log(response.data.results);
} else {
console.log(response);
}
})
.catch((error) => {
console.log(error);
});
}
if (files.length > 0) {
handleMultipleSubmit();
}
}, [files]);