0

In client side I send a request with $http:

Upload.upload({
       url: 'http://localhost:3000/upload',
       fields: {
            'username': $scope.username
       },
       file: file
})

In server side, this is the route:

app.route('/upload')
    .get(function (req) {
        for (var key in req)
            console.log(key);
})

But I cannot see any key name file in req? What is the reason for this difference between them two?

1 Answers1

0

You need to add headers to upload files using post , need to make multipart/form-data request ,

   var fd = new FormData();
     fd.append("file", file);

    $http.post(uploadUrl, fd, {
        withCredentials: true,
        headers: {'Content-Type': undefined },
        transformRequest: angular.identity
    })

See more on this answer

Community
  • 1
  • 1
Jayantha Lal Sirisena
  • 21,216
  • 11
  • 71
  • 92