Reputation: 3715
I am using angularJs to make a http Post
request to the server. I am able to get the file uploaded on the NodeJs server, but not able to figure out how to fetch the keywords
from the request.
Client Code (AngularJs):
var file = $scope.myFile;
var uploadUrl = HOST_URL+"/filter-reports";
var fd = new FormData();
fd.append('file', file);
fd.append('keywords','searchkey1, searchkey2');
$http.post(uploadUrl, fd, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
})
.success(function(data){
console.log('Fetched the data .. '+data);
})
.error(function(){
console.log('could not fetch the data .. ');
});
Please let me know to to extract FormData
parameters on Node.js and let me know where am I going wrong as I am new to NodeJs.
Upvotes: 2
Views: 2570
Reputation: 15725
install body-parser
module on your node server.
Then on your server, require the module var bodyParser = require('body-parser');
This will parse your request body so you would be access the params inside the body.
in your route for your post request, you can get the keywords parameters as follows,
var keys=req.body.keywords;
Upvotes: 1