简体   繁体   中英

I got problem sending FormData from my ReactNative app with Axios and get it in my server with multer

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM