How I could send files successfully if my payloads look like this?
const payload = {
documents: [
{ doc_category: someValue, doc_files: [files1.pdf, file2.pdf, file3.pdf] }
]
}
I have tried something like this but it is not working
const formData = new FormData()
formData.append('document[0][doc_category]', someValue)
files.forEach((doc, key) => {
formData.append(`document[0][doc_files][${key}]`, doc)
}
axios.post('/url', formData, {headers: { 'Content-Type': 'multipart/form-data' }})
.then( // handling response here )
Please Note that I am not asking how to send files using axios, but how to append data to FormData, in which the data is array object containing files.
I have tried JSON.stringfy but it's failed too. Any help would be very appreciated