使用xhr上传的node-express中的接收文件 [英] receiving file in node-express uploaded with xhr
本文介绍了使用xhr上传的node-express中的接收文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 xmlhttprequest 上传文件,我试图在我的 node-express 服务器中接收它.但由于某种原因,我无法检索服务器中的文件内容.不知道我在哪里错过了它.
I have a xmlhttprequest which uploads the file and I am trying to receive it in my node-express server. but for some reason I am not able to retrieve the file content in the server. Not sure where I am missing it.
app.post('/api/uploadfiles', function(req, res) {
console.log("apicalled");
console.log(req);
console.log(req.body);
console.log(req.files);
console.log(JSON.stringify(req.files));
});
推荐答案
为了让您看到文件,您需要添加另一个解析多部分请求的中间件.尝试使用连接多方模块,如下所示:
In order for you to see the files, you will need to add another middleware that parses multi-part request. Try using connect-multiparty module like so:
var multipart = require('connect-multiparty'); //for files upload
var multipartMiddleware = multipart();//for files upload
app.post('/api/uploadfiles', multipartMiddleware, function(req, res) {
console.log("apicalled");
console.log(req);
console.log(req.body);
console.log(req.files);
console.log(JSON.stringify(req.files));
});
这篇关于使用xhr上传的node-express中的接收文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文