我想上传一个像这样的表格(JADE)的文件:
form(action="/file-upload", name="upload", method="post", enctype="multipart/form-data")
input(type="file", name="theFile")
input(type="submit", name="Upload")
这是我的app.js:
app.use(express.methodOverride());
app.use(express.multipart());
app.use(express.bodyParser());
这就是我处理请求的方式:
app.post('/file-upload',function(req,res){
console.log('FIRST TEST: ' + JSON.stringify(req.files));
console.log('second TEST: ' +req.files.theFile.name);
});
这是我的Node.js控制台:
FIRST TEST: undefined
TypeError: Cannot Read Property 'theFile' of undefined....etc....
哦,顺便提一下Connect模块发出警告:
connect.limit() will be removed in connect 3.0
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
我在这里做错了什么?我已按照here,here,here提供的建议,但没有任何作用。谢谢你的帮助......
更新: 我刚刚将LOGGER添加到我的应用程序结果中,所以看起来我收到了请求:
127.0.0.1 - - [Wed, 19 Feb 2014 11:02:11 GMT] "POST /file-upload HTTP/1.1" 500 -
"http://localhost:3000/admin/news-add" "Mozilla/5.0 (Windows NT 6.1; WOW64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36"
答案 0 :(得分:3)
我现在看到......我有
app.use(express.multipart());
app.use(express.bodyParser());
app.use(express.methodOverride());
在app.use(app.router);
之后应该在之前声明,如下所示:
app.use(express.multipart());
app.use(express.bodyParser());
app.use(express.methodOverride())
app.use(app.router);
现在,它的工作就像一个魅力......