Reputation: 1280
I am doing image uploads as outlined in the documentation for the App Engine Images API, using getServingUrl() to generate an upload url, and then forwarding the request to my own handler. I am wondering if there is a way to verify that the uploaded blob in fact is an image or do I have to read the bytes and use that to figure out the file type.
Upvotes: 2
Views: 339
Reputation: 324
Most image files have a magic number or signature in the bytes that is easy to find and might be faster to read than trying to decode the entire image (i.e. trying to use the resize operation; since that will likely fail fast on NOT an image but will actually DO the operation if it is an image).
There are only a finite number of image types you'd really want to support I suspect; here are some example magic numbers on wikipedia:
http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Magic_numbers_in_files
Upvotes: 3
Reputation: 1525
In Python you can just perform a simple transform (resize works) on the blob data using the images API and if the blob is not an image a NotImageError will be raised. There is likely an equivalent in Java.
Upvotes: 1