2017-02-15 38 views
1

enter image description here enter image description here所以我要开始我的身体解析器和还我使用“multer”Bodyparser为多的NodeJS

我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}); 

身体解析器。 JS

app.use(bodyParser.urlencoded({extended:true,limit: '20MB',parameterLimit:10000})); 
app.use(bodyParser.json()); 

我有这样的

路线3210
router.post('/edit',[auth.isAuthenticated,pfImage.single('pImage')],actions.edit); 

功能就是这样

function edit(req,res) 
{ 
    console.log(req.body); 
} 

控制台日志输出:

块引用

{“------ WebKitFormBoundaryGS8GEzQls8xRP6nt \ r \ nContent处置:形状数据; 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;名字= \ “\” \ r \ n \ r \ n \ r \ n ------ WebKitFormBoundaryGS8GEzQls8xRP6nt - \ r \ n“}

如何可以解析这是req.body

+0

你想通过url传递图像数据吗? – carebdayrvis

+1

nope通过邮递员我加了sc reenshots –

回答

2

的问题是,你发送一个多部分/格式数据请求您要替换的Content-Type并将其设置为一个不同类型(应用程序/ x-WWW窗体-urlencoded),这是一个完全不同的格式。如果你删除这个覆盖,它应该没问题。

+0

很好的答案谢谢 –