Re: How to detect broken images before storing to blob store?

43 views
Skip to first unread message
Message has been deleted

Bryce Cutt

unread,
Sep 28, 2012, 4:05:49 PM9/28/12
to google-a...@googlegroups.com
First read the first few bytes of the file using a BlobReader and check to make sure they contain a "magic number" for an image format you support. This quickly rules out non-image file types. If this test fails then discard the image.

Then load the image data and create an Image object based on it. If this throws a BadImageError then the image is not valid or not a format that GAE can operate on so discard it. This step might also throw a LargeImageError which tells you that the image is over 50 megapixels and thus too large for GAE to operate on. You might not care about that if you are not going to use the images library.

When I say "load the image data and create an Image object based on it" I specifically mean loading the data with a BlobReader and using the Image constructor that takes image_data as input (not blob_key input) because if you create an Image object using a blob_key only it will not throw the BadImageError until after you try performing an operation on the image.

- Bryce


On Friday, September 28, 2012 4:38:17 AM UTC-7, swapnilkhamkar wrote:
Is there any way in which we can detect a broken image before storing to blob store?

I am storing images to blob store. I want to detect the broken images and discard them from being stored. 
Is there any such way to do it?
Reply all
Reply to author
Forward
0 new messages