i am using axios and FormData to send my files from client to server, on the server i am using multer for handling the datas, my client's code for sending is like: the file's title(the first field of append) for pdf and image are the same as server, and when i send data on the server after multer that append a files to req, i am not able to get the files and its always undefined, the server code's looking like:
and the body of the request after requesting to server is like:
and headers of the request in the backend is: and my form data before sending looks like:
I also tried these for FormData:
bodyFormData.append('pdfFile',pdfDetail.filepath,pdfDetail.filename)
bodyFormData.append('imageFile',{uri:coverDetails.filepath,name:coverDetails.filename,type:coverDetails.filetype})
How can I solve this? Thank you guys
you need to specify content-type for axios requests.
try this:
axios({
method: 'POST',
url: 'uploadANewBook',
data: bodyFormData,
headers: {
'x-access-token': token,
'Content-type': 'multipart/form-data'
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.