Reputation: 11
I have a page where user uploads files and are passed to Node API which does some operations like database insert and finally has to send the files to another node rest API for virus check.
I can see file content and attributes in req.files
in the first API call but struggling to pass req.files
to another node API URL using request.post
.
var uploadFile= function(req, res) {
var files = req.files.upload;
Async.series(
[ function (callback) {..},
function (callback){viruscheck(files,callback);}
....
//viruscheck method
var viruscheck= function(files, callback) {
request.post({url: "http://loclahost:1980/viruscheck/upload.json",
qs: {
..
},
headers: {'enctype-type': 'multipart/form-data'},
form:{
upload:files
}
},function(error, response, body){
if(error) {
console.log(error);
callback(error)
} else {
console.log(response.statusCode, body);
callback()
}
});
}
In API http://loclahost:1980/viruscheck/upload.json I see file content in body rather than req.files
.
How can I get the files in request.files
in my second API call?
Upvotes: 1
Views: 2891
Reputation: 21
Use:
headers: {'Content-Type': 'multipart/form-data'},
Instead of:
headers: {'enctype-type': 'multipart/form-data'},
enctype is an HTML form thing.
See this answer for more: Uploading file using POST request in Node.js
Upvotes: 2