onurzorluer / react-image-file-resizer

Resize Local Images with React 🌄 🌅
MIT License
313 stars 41 forks source link

Handle failure with non-image files #98

Open nathanmanousos-luma opened 4 weeks ago

nathanmanousos-luma commented 4 weeks ago

Is your feature request related to a problem? Please describe. Non-image files with an image file extension like my-text-file.png will fail silently, leading to user confusion.

Describe the solution you'd like I'd like some form of error response that I can handle in my UI.

A quick look at the code led me to think this section (https://github.com/onurzorluer/react-image-file-resizer/blob/master/src/index.js#L151) is failing silently if the file is not actually an image. Perhaps error handling can be introduced for situations where image.onload might never be called, and perhaps a null value can be sent to responseUriFunc or a second callback for errors etc.

I'll try this fix myself if I get time soon.