Failed to get form data submitted from angular server to node

I ship form-datawith image-data.
But I can not get the data on the node server when sending internally FormData.

I could see the data on the controller angularon console.log.

angular code:

$scope.saveInfo = function(){
  var formData = new FormData;
  console.log('Update function');
  for(key in $scope.seller){
    formData.append(key, $scope.seller[key]);
  }
  console.log(key, $scope.seller);
  var file = $('#file')[0].files[0];
  formData.append('image', file);

  $http.put('/api/seller/businessInformation', formData, {
    transformRequest: angular.Identity,
    headers: {
      'Content-type': undefined
    }
  }).then(function(res){

  });
}

Node.js: I could see the image data on console.log(req.files);,
but it console.log(req.body);prints [object object].

+6
source share
3 answers

The problem is with ng model data binding.
I linked the data as follows: "seller.abc"
Instead, I did seller.a, and it worked.

-4
source

-

(i) JSON.stirngify(req.body) .

(ii) , , req.body.whateverField

FormData ,

console.log(req.files.file.name);

FormData

var a = JSON.parse(req.body.name);
console.log(a);
+6

req.bodyis an object. If your form data contains a name and age. then you can get these values ​​in node as below

req.body.name
req.body.age
0
source

All Articles