2

I am new to angular . In my application, i want to upload a file to the server . according to the api , 'Content-Type' header should be null or not sent. I googled and developers proposed to set the header as undefined . The below is my code

return $resource(apiHost +'/tessters/:patId?action=:action&format=:format', {patId: '@patId' , action: '@action' ,format: '@format'}, {
            save: {
                method: 'POST',
                transformRequest: angular.identity,
                headers: {'Content-Type' : undefined,'Authorization': authorizationToken},
            }
        });

but in the developer view , i am able to observe that the 'Content-Type' is set to text/plain;charset=UTF-8

enter image description here

and i could not be able to find any ways to remove 'Content-Type' header , If anyone knows the solutions please help me out

Thanks in advance

1 Answers1

2

please check below

      var file = angular.element(document.querySelector('#file')).prop("files")[0]; $scope.files = []; $scope.files.push(file)
      $http({
                method: 'POST',
                url: siteRootURL,
                headers: {'Content-Type': undefined},
                transformRequest: function (data) {formData.append('model', angular.toJson(data.model));                       
                    formData.append('file', data.files[0]);
                    return formData;
                },
                data: {model: $scope.user,files: $scope.files}
            })

Please also check you have set form enctype='multipart/form-data' attribute.

Deepak Dholiyan
  • 1,774
  • 1
  • 20
  • 35