[英]Uploading files with ExpressJS
I'm using latest NodeJS and ExpressJS to write a small app. 我正在使用最新的NodeJS和ExpressJS来编写一个小应用程序。 Currently I stuck on uploading a file.
目前我坚持上传文件。 :>
:>
routes are configured this way 路由以这种方式配置
app.get('/Share', share.index);
app.post('/Share/Process', share.processFile);
The index view looks like the following 索引视图如下所示
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')
When I follow the ExpressJS API documentation, I should have access to the file, by using req.files , which is undefined within the share.processFile method 当我按照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'});
};
尝试将表单编码更改为multipart/form-data
,IIRC应该设置为传输文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.