2

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.

2 Answers 2

1

req.body.keywords if you are using express with body parser

Sign up to request clarification or add additional context in comments.

Comments

1
  1. install body-parser module on your node server.

  2. 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.

  3. in your route for your post request, you can get the keywords parameters as follows,

    var keys=req.body.keywords;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.