简体   繁体   English

我在使用 Axios 从我的 ReactNative 应用程序发送 FormData 并使用 multer 将其放入我的服务器时遇到问题

[英]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.

相关问题 Formdata 与 Axios 和 ReactNative - Formdata With Axios and ReactNative 当 multer 是 localhost 时,如何将文件从 multer 发送到托管在服务器上的网站文件夹 - How can i send a file from multer to my website folder which is hosted on a server while multer is localhost multer无法在我的应用程式中运作 - multer is not working in my app 通过套接字将视频从 ReactNative 应用程序发送到 Python 服务器 - Sending video from ReactNative app to Python Server via socket 为什么我的formdata.append没有将键值对发送到服务器? - Why my formdata.append is not sending key value pair to server? 如何从 FormData() 访问我的数据(用户名、密码等;)到我的快速服务器 - How to get access my data (username, password etc;) from FormData() into my express server 我如何通过我的反应应用程序上的 Axios 从 Imgur 的 API 发出 GET 请求 - How do i make a GET requests from Imgur's API via Axios on my react app 我无法在我的购物车中将我的产品减少 1,因为我遇到了一个未定义的问题 - i can't get to reduce my product by 1 in my cart because i got an undefined problem 我如何让我的快递服务器从我的React客户端应用程序获取请求? - How do I get my express server to GET a request from my React client app? 使用 axios 将 FormData 从 ReactJs 发送到 NodeJs controller - Sending FormData from ReactJs to NodeJs controller using axios
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM