[英]Why request body is null in file upload with postman in Node.js
I am trying to upload file from postman to the Node.js server.我正在尝试将文件从邮递员上传到 Node.js 服务器。 I am using multer and body-parse to parse the body of the request.我正在使用 multer 和 body-parse 来解析请求的正文。
Use case:用例:
Please help to identify the meaning of req.body=[Object: null prototype]请帮忙识别req.body=[Object: nullprototype]的含义
I ran into a similar issue. 我遇到了类似的问题。 If you console.log(req.body) in the function. 如果在功能中使用console.log(req.body)。 you will notice that the body is equal to [Object: null prototype] because Multer is handling the request as the form is multipart. 您会注意到该主体等于[Object:null prototype],因为Multer正在处理请求,因为表单是多部分的。 So, if you console.log(req) object, you can find the values that can be retrieved and you can just do req.{Name_of_field} to get values. 因此,如果您使用console.log(req)对象,则可以找到可以检索的值,并且只需执行req。{Name_of_field}即可获取值。
If you need clarification please let me know, I might be able to share the code. 如果您需要澄清,请告诉我,我也许可以共享代码。
Shivam Mahajan wrote almost as it goes, but: Shivam Mahajan撰写了几乎所有内容,但:
You can access text fields not in the req.{Name_of_field}
, but req.body.{Name_of_field}
, as said in multer docs . 您可以访问文本字段,而不是req.{Name_of_field}
中的文本字段,而是req.body.{Name_of_field}
中的文本字段,如multer docs中所述。
you can use express busboy add these to your main page您可以使用 express busboy 将这些添加到您的主页
const expressBusboy = require('express-busboy');
expressBusboy.extend(app); expressBusboy.extend(app);
and this will parse your form-data这将解析您的表单数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.