I have a POST request, that I'm sending from my frontend, with axios, where I send a FormData
object, with an array of files, and some additional parameters
const files = this.state.fileObjects
const fields = {
"name": this.state.name,
"email": this.state.email,
"message": this.state.message
}
const data = new FormData()
//implement multer on server side
for (const [index, file] of files.entries()) {
data.append(`files[${index}]`, file)
}
for (const [key, value] of Object.entries(fields)){
data.append(key, value)
console.log(data)
I then use a post request, to send the data to my backend, where i let multer
handle the FormData
object
axios({
method: 'post',
url: '/api/form',
data: data,
config: { headers: {'Content-Type': 'multipart/form-data' }}
})
.then(function (response) {
//handle success
console.log(response);
})
.catch(function (response) {
//handle error
console.log(response)
})
when everything is appended to the formdata, object nothing is received properly on the backend. What am i doing wrong?