私は最新のNodeJSと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のドキュメントに従うと、share.processFileメソッド内で定義されていないreq.filesを使用して、ファイルにアクセスできるはずです。
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'});
};