0
我正在使用最新的NodeJS和ExpressJS編寫一個小應用程序。目前我堅持上傳文件。 :>使用ExpressJS上傳文件
路由這種方式配置
app.get('/Share', share.index);
app.post('/Share/Process', share.processFile);
索引視圖看起來如下
form.form-horizontal(action='/Share/Process', method='post')
legend share a file
div.control-group
label.control-label(for='item[actual]') File
div.controls
input(type='file', name='item[actual]', required='required')
當我按照ExpressJS API文檔,我應該對文件的訪問,通過使用req.files,在share.processFile方法中未定義
exports.processFile = function(req,res){
console.log(req.files); // undefined
console.log(req.body.item.actual); // filename as string
res.render('share/success', {navigation: { shareClass : 'active'}, downloadKey: 'foo'});
};
你確定在定義路由之前調用'express.bodyParser'(否則'req.files'不會被設置)? – ebohlman
是bodyParser被調用而沒有任何參數 –