Question

Is there any way to determine if a JPEG file is corrupt after reading it via the FileReader API in JavaScript?

I'm thinking about something like what "libjpeg" does. It provides warning messages if something is wrong with the JPEG file.

Was it helpful?

Solution

There are some libraries which do JPEG decoding in Pure JavaScript.

E.g. https://github.com/notmasteryet/jpgjs (there are others)

You can simply decode the FileReader fed data in your JavaScript code and see if the output is sane.

Depending of the degree of corruption, what cases you want to trap, it should be possible on client-side.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top