简体   繁体   中英

receiving file in node-express uploaded with xhr

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));
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM