所以我想从我的 body 解析器开始,而且我正在使用“multer”
我的multer选项:
var multer = require('multer');
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, '/root/Unicon-Oauth/Resources/profile_images/')
},
filename: function (req, file, cb) {
cb(null, file.fieldname + '-' + Date.now())
}
});
var pfImage = multer({storage:storage});
server.js 的正文解析器
app.use(bodyParser.urlencoded({extended:true,limit: '20MB',parameterLimit:10000}));
app.use(bodyParser.json());
我有一条这样的路线
router.post('/edit',[auth.isAuthenticated,pfImage.single('pImage')],actions.edit);
功能就是这样
function edit(req,res)
{
console.log(req.body);
}
控制台日志输出:
Blockquote
{"------WebKitFormBoundaryGS8GEzQls8xRP6nt\r\nContent-Disposition: form-data; name":"\"_id\"\r\n\r\n58a4735cfa328b7e9eaf6a3a\r\n------WebKitFormBoundaryGS8GEzQls8xRP6nt\r\nContent-Disposition: form-data; name=\"city\"\r\n\r\nKayseri\r\n------WebKitFormBoundaryGS8GEzQls8xRP6nt\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nali\r\n------WebKitFormBoundaryGS8GEzQls8xRP6nt\r\nContent-Disposition: form-data; name=\"\"\r\n\r\n\r\n------WebKitFormBoundaryGS8GEzQls8xRP6nt--\r\n"}
如何将其解析为 req.body ?
最佳答案
问题是您正在发送多部分/表单数据请求但是您正在覆盖 Content-Type 并将其设置为不同类型(应用程序/x-www-form-urlencoded),这是一种完全不同的格式。如果删除此覆盖,应该没问题。
关于node.js - 用于多部分 Nodejs 的 Bodyparser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42260888/