dfa1234 / ngx-image-compress

Angular library for uploading and compressing images
https://image-library.app
MIT License
87 stars 36 forks source link

Image compression fails on Firefox Android #44

Closed adamk22 closed 2 years ago

adamk22 commented 3 years ago

I'm running into an issue with Firefox on Android (Related #38 ). Apparently, larger files 3-4MB's will cause the app to remain in a 'stuck' state because the compression somehow doesn't work (it doesn't resolve or reject the promise).

In the case below, both console.logs will not get outputted because the promise doesn't resolve or reject:

async compressImage(file: string, fileSource: File): Promise<void | File> {
    const orientation = await this.imgCompress.getOrientation(fileSource);
    return this.imgCompress
        .compressFile(file, orientation, 50, 50)
        .then((image) => {
                         console.log('image', image);
            const imageBlob = this.dataURItoBlob(image.split(',')[1]);
            const imageFile = new File([imageBlob], fileSource.name, {
                type: 'image/jpeg',
            });
            return imageFile;
         })
                 .catch((err: any) => {
                     console.log('err compress', err);
                  })
    }

Looking in the source code I noticed that in the compress() function the onload event won't fire when larger images are passed to the compressFile() function. Smaller images somehow work and the onload event is fired. I'm not sure why this is the case in firefox considering it works how it's suppose to work in Chrome (also with larger images).

dfa1234 commented 3 years ago

It's not linked to #38, there the problem is related to stackbilz server. You need to make a test from your own server

dfa1234 commented 2 years ago

@adamk22 you can now use this link to make your performance tests

https://image-library.app/

dfa1234 commented 2 years ago

Tested on BrowerStack on a real device and it's working fine, with a image of 5mb. Closing the issue

image