Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An error occured when using resize and applyExifRotation function if the image uploaded is too large #1360

Closed
zuolei828 opened this issue Feb 16, 2016 · 1 comment

Comments

@zuolei828
Copy link

Thanks for your work and share!

I used the Upload.resize and Upload.applyExifRotation function for my mobile app, and I found that when the image uploaded is too large, the HTML5 canvas drawImage function will not work right. Then the canvas toDataUrl will return only a 'data,;' string, so the upload.dataUrltoBlob function will throw an error.

It seems to be a memory problem, but I think you should catch the error and reject the promise. Here is your code:

var deferred = $q.defer();
upload.dataUrl(file, true).then(function (url) {
  resize(url, width, height, quality, type || file.type, ratio, centerCrop, resizeIf)
    .then(function (dataUrl) {
      if (file.type === 'image/jpeg' && restoreExif) {
        try {
          dataUrl = upload.restoreExif(url, dataUrl);
        } catch (e) {
          setTimeout(function () {throw e;}, 1);
        }    
      }    
      deferred.resolve(upload.dataUrltoBlob(dataUrl, file.name, file.size));
    }, function (r) {
      if (r === 'resizeIf') {
        deferred.resolve(file);
      }    
      deferred.reject();
    });  
}, function () { 
  deferred.reject();
});  
return deferred.promise;

And I think it is better to change to the blow code:

     try {
          var blob = upload.dataUrltoBlob(dataUrl, file.name, file.size);
      } catch (e) {
          deferred.reject();
      }
      deferred.resolve(blob);
@danialfarid
Copy link
Owner

Fixed at 12.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants