Search code examples
angularjsdjangoangular-file-upload

Listen to API response using angular-file-upload module


I'm building a WebApp using AngulasJs and Django and I'm currently relying on angular-file-upload to upload image to my api like so :

var uploader = $scope.uploader = new FileUploader({ 
                   url: 'http://localhost:8000/image', 
                   headers: { 'X-CSRFToken': $('input[name="csrfmiddlewaretoken"]').attr('value')
                            }, 
               }); 

The files is uploaded fine but then what I have been unable to figure out is how to get the response from the api (Some data that I need to insert into my html). I first supposed I would be able to register some kind of listener using angular-file-upload module but I didn't find anything that could allow me to do that.

Does the angular-file-upload module provide a way to do this or do I need to rely on an other angularjs functionality ?

Thanks in advance for any help !


Solution

  • Using angular-file-upload-shim, you could declare callback functions like this:

    $scope.upload = $upload.upload({
        url: 'rs/medias/upload',
        method: 'POST',
        file: file 
    }).progress(function (evt) {
    }).success(function (data, status, headers, config) {
    })
    .error(function (data, status, headers, config){
    });