[英]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,我正在使用 axios 和 FormData 将我的文件从客户端发送到服务器,在服务器上我使用 multer 处理数据,我的客户端发送代码如下:pdf 的文件标题(附加的第一个字段)和图像是和服务器一样,
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:
当我在将 append 文件发送到 req 之后在服务器上发送数据时,我无法获取文件并且它始终未定义,服务器代码看起来像:
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:
我还为 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.您需要为 axios 请求指定内容类型。
try this:尝试这个:
axios({
method: 'POST',
url: 'uploadANewBook',
data: bodyFormData,
headers: {
'x-access-token': token,
'Content-type': 'multipart/form-data'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.