0

I am trying to upload a file with angular and asp.net mvc. The file was uploaded in the folder and I am returning an action result from the c# controller. But I am getting the error Cannot read property 'then' of undefined.

uploadFile = function (file) {
    var self = this;
    var formData = new FormData();
    formData.append('file', file);

    $http.post(self.baseUrl + "Admin/uploadFile", formData,
    {
        withCredentials: true,
        headers: { 'Content-Type': undefined },
        transformRequest: angular.identity
    }).then(function (data, status, headers, config) {
        conslole.log(1);
    })
}
  • This doesn't have anything to do with the file upload function, it has to do with the `.success()` function in angular, which was deprecated more than a year ago, and was recently removed completely. http://stackoverflow.com/questions/35329384/why-are-angular-http-success-error-methods-deprecated-removed-from-v1-6 – Claies Feb 19 '17 at 20:05
  • bottom line, don't use `.success()`, use `.then()` instead. – Claies Feb 19 '17 at 20:06
  • Possible duplicate of [Why are angular $http success/error methods deprecated? Removed from v1.6?](http://stackoverflow.com/questions/35329384/why-are-angular-http-success-error-methods-deprecated-removed-from-v1-6) – Claies Feb 19 '17 at 20:06
  • Thank you. I replaced success with then and I am getting : Cannot read property 'then' of undefined –  Feb 19 '17 at 20:11
  • 1
    are you sure you injected `$http` into your controller that is calling this function? – Claies Feb 19 '17 at 20:15
  • thank you . I injected $http in the service but I didn't injected to the controller –  Feb 19 '17 at 20:18
  • Can you post your full code including controller, service and any other related bit ? – Yaser Feb 19 '17 at 21:31

0 Answers0