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?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/2rgNDgisFPUJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to