2017-02-15 88 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

很好的答案謝謝 –