danialfarid / ng-file-upload

Lightweight Angular directive to upload files with optional FileAPI shim for cross browser support
MIT License
7.87k stars 1.6k forks source link

Error callback takes long to be called when using Android #1947

Open martosoler opened 7 years ago

martosoler commented 7 years ago

Hi,

I'm doing some UI changes to display a notification when the upload fails, like coloring some div with red and so:

$scope.uploadImage = function(file) {
      $scope.failed = false;

      return Upload.upload({
          url: '/api/images/upload/',
          data: { file: file }
        })
        .then(function (resp) {
            $scope.uploaded = true;
            $scope.url = resp.data.url;
        }, function (resp) {
            $scope.uploaded = false;
            $scope.failed = true;
        }, function (evt) {
            var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
            $scope.percentageUpload = progressPercentage;
        })
        .catch(function(error) {
          alert('Oops: ' + JSON.stringify(error));
        });
    };

Using a desktop browser, everything works fine, the changes are visible right after the server returns the error but when using a mobile (android 6.0.1) the upload just hangs as if it was uploading something and then after some time, it handles the error and shows the changes I made.

What could be the difference in handling the HTTP response between desktop and mobile that could be causing this?