Pick up angular-file-upload return

Asked

Viewed 327 times

1

I’m using the angular file upload, it works very well, but I need the return that the server makes available to me. I am using the following code:

  $scope.uploader = new FileUploader({
    url: 'https://api.imgur.com/3/image',
    alias: 'image',
    headers: {
        Authorization: 'Client-ID XXXXXXXXXXXXXXXXXXXX',
    },
    autoUpload: true,
  });

The answer:

{"data":{"id":"sK1PnoE","title":null,"description":null,"datetime":1454191817,"type":"image\/png","animated":false,"width":400,"height":400,"size":8981,"views":0,"bandwidth":0,"vote":null,"favorite":false,"nsfw":null,"section":null,"account_url":null,"account_id":0,"comment_preview":null,"deletehash":"LLLGwJ7PdzYsord","name":"","link":"http:\/\/i.imgur.com\/sK1PnoE.png"},"success":true,"status":200}

Edited ---

I am unable to access the methods of Callbacks, tried in the following ways:

$scope.uploader.onCompleteItem = function(fileItem, response, status,headers) {
      console.log(response);
  };

  $scope.uploader = new FileUploader({
    //xxxxx
  }).onSuccessItem = function(fileItem, response, status,headers) {
    console.log(response);
  };

1 answer

2


The response data of fileUploader are received within the plugin’s own functions, whether for success, error, progress and other methods.

See the functions of callback of this page: https://github.com/nervgh/angular-file-upload/wiki/Module-API

Example:

$scope.uploader.onSuccessItem = function(fileItem, response, status,headers) {
    //sua função aqui...
};

Then you just have to check the response or status, for example, to check. As there is a callback for each step, to identify an error, you must use the callback onErrorItem, for progress use onProgressItem, and so on.

  • Update the post, take a look. Thank you for the answer!

  • IO that the console shows @SCOFIELD ?? And what you need to get information from? Only the status whether it worked or not?

  • It actually worked :v I was trying to access the $Cope method before setting it (Genius). Thanks for the help!

  • Haha not so. = D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.