1

I have this $http POST request that works

$http.post('api/saveFile', formData, {

           transformRequest: angular.identity,

           headers : {
            'Content-Type' : undefined
           }
}

Meanwhile when I am using $resource instead I am getting a 500 error, basically my backend is seeing a null value from the frontend.

Here is the code for the resource

     this.resource = $resource('api/myUrl', {}, {

        'saveFile': {
            method: 'POST',
            url: 'api/myUrl/saveFile',
            data: {file : '@file'},
            transformRequest: angular.identity,
            headers: {'Content-Type': undefined}
        }
    });

And here is where the resource method is called. Note I tested it so that the code before and after the request is the same

MyService.resource.saveFile(
            {file : formData},
                function successCallback(response) {
                    console.log(response);
                },
                function errorCallback(response) {
                    console.log(response);
                })

So my code here is suppose to upload a file to my backend, then save it to the drive. That works with the $http but not with the $resource

capa_matrix
  • 115
  • 3
  • 10
  • Does [this](http://stackoverflow.com/questions/21115771/angularjs-upload-files-using-resource-solution) helps? – Master Po May 11 '17 at 19:30
  • @Pete , no it doesn't, it gives me more info on how to format for file uploading but not on my problem. I tried using similar syntax as demonstrated in one of the answers but it didn't help. The problem is I don't understand how I should be sending the data exactly. – capa_matrix May 11 '17 at 19:58

0 Answers0