

所以我想从我的身体解析器开始,同时我用的是“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的Body解析器
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);
}控制台日志输出:
区块报价 {"------WebKitFormBoundaryGS8GEzQls8xRP6nt\r\nContent-Disposition:表单数据;name":"\"_id\"\r\n\r\n58a4735cfa328b7e9eaf6a3a\r\n------WebKitFormBoundaryGS8GEzQls8xRP6nt\r\nContent-Disposition:表单数据;name=\"city\"\r\n\r\nKayseri\r\n------WebKitFormBoundaryGS8GEzQls8xRP6nt\r\nContent-Disposition:表单数据;name=\"name\"\r\n\r\nali\r\n------WebKitFormBoundaryGS8GEzQls8xRP6nt\r\nContent-Disposition:表单数据;name=\"\"\r\n\r\n\r\n------WebKitFormBoundaryGS8GEzQls8xRP6nt--\r\n"}
如何将此解析为req.body?
发布于 2017-02-15 22:55:51
问题是,您正在发送多部分/表单数据请求,但您正在覆盖内容类型,并将其设置为不同的类型(application/x-www-form-urlencoded),这是一种完全不同的格式。如果您删除了这个覆盖,应该会没事的。
https://stackoverflow.com/questions/42260888
复制相似问题