dfa1234 / ngx-image-compress

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

File not uploading from android device #80

Closed aviralgoyal closed 2 years ago

aviralgoyal commented 2 years ago

Hi

I am currently working on a project in Angular 12. I used the function uploadAndGetImageWithMaxSize(). It works fine in the windows enviornment, the image gets uploaded and resized, but when I run it on an android device the upload dialog opens and select the image and press done, nothing happens. I'm not even getting any error codes or anything.

Is there a known issue for android devices?

dfa1234 commented 2 years ago

I don't think there is an issue. Please try to open this link with your android browser: https://image-library.app/ If you still have issues, please details your android specification and which browser you use.

aviralgoyal commented 2 years ago

You're correct it is working from the link you sent me, must be something in my code. I'll try adding some logging at each step to figure out the issue.

Also I wanted to know if there is a way to get the file name of the file uploaded from within the function. Because I need the file extension for storage.

dfa1234 commented 2 years ago

@aviralgoyal filename would be a good addition. I'm adding this for fututes feature. Meantime you can write you own "upload" function and use the this.imageCompress.compressFile function from the library.

andresud commented 2 years ago

I'm having the same issue using Ionic/Angular project, I can upload a photo from file but not from gallery nor from camera... The app you passed is working fine.

aviralgoyal commented 2 years ago

@andresud I found the problem, in my case I used a mobile debugging option and when I'm using the Angular Material button, the library responds with a message, user interaction is required, or something on those lines. I removed the angular button and put a normal button, it works fine. @dfa1234 There is some kind of warning added to the library, which is behaving differently in case of an angular material type button.

There is one more enhancement that I would like to request, in the uploadAndGetImageWithMaxSize(), if you could expose the size and quality parameters to help the developer choose how much the size or quality should be reduced each time the loop runs for reducing the image size to the desired size. Right now it is set at 50%, which i feel is bit too much, I think it should be somewhere around 20% or user definable which would be ideal.

dfa1234 commented 2 years ago

@aviralgoyal indeed we could add optional quality parameter. At first this function was done for being a lot more simple to use, with minimal configuration, when, on the contrary, this.compressImage give a lot more of control. But adding a optional parameter is not a problem. Feel free to submit some PR if you have some minutes so we will not forget it. even if the PR is not 100% ready it will help

aviralgoyal commented 2 years ago

@dfa1234 I will try my level best and find time, I am yet to make my first PR, so it might take me a while to read and understand, how to do this.

I tried upload a file < 1MB on https://image-library.app/
using the option Uploading, Compressing and returning with max size of 1 MegaByte.

It is giving an error as even though it is already smaller than 1mb. It is trying to reduce the file further and as it did not succeed and goes to the error handler instead of just succeeding without compressing.

dfa1234 commented 2 years ago

@aviralgoyal interesting, indeed if image is already < to 1mb the promise should resolve and not reject, we will add a PR for this, or you can submit it, it can be a good exercise for you too :)

dfa1234 commented 2 years ago

Filename available in #89