views:

123

answers:

2

I have a general purpose file storage backed by Google App Engine Blobstore, when I show users it's contents I would like to differentiate images from other files — I would like to show thumbnail for each image.

Python get_serving_url function does not care (at least at dev server) if given blob is in fact an image, java's getServingUrl throws en exception...

So my question, is: How to detect in python if a blob store entry is an image, so I could get a serving_url and use it in the UI?

EDIT:

On production python is throwing NotImageError on get_serving_url call with not supported blob—it's just not documented and it does not do that on dev server.

+2  A: 

Depending on how the images were uploaded to your Blobstore, they may all contain their MIME types, which you could try to use as a method of determining which items are most likely to contain valid image data using BlobInfo:

blob_info = BlobInfo.get(blob_image_key)

# All valid image formats for the GAE Images service.
image_types = ('image/bmp', 'image/jpeg', 'image/png', 
    'image/gif', 'image/tiff', 'image/x-icon')

if blob_info.content_type in image_types:
    # Obtain your serving URL.
Andrew
Thx for the tip :), but I was wondering is there a more complete solution involving an API call, something that would not involve me guessing which content types are supported by the Images service serving_url.
WooYek
To the best of my knowledge, there is no API call from GAE that you can run to check whether the Images service can render an image. I've updated my post to reflect only valid images from the GAE service.
Andrew
@Andrew, thx! Are you basing this on this [Image Formats](http://code.google.com/intl/pl-PL/appengine/docs/python/images/overview.html#Image_Formats) list, or is there any other?
WooYek
A: 

You could putting the call inside a try...except block, catching the exception which is thrown when the object is found to not be an image.

Matt H
There is no exception thrown... Quote: »Python get_serving_url function does not care (at least at dev server) if given blob is in fact an image, java's getServingUrl throws en exception...«
WooYek
That sounds like a bug, you should report it.
Matt H
Just deployed the solution on production and there is `NotImageError` being thrown in python as well. @Matt is right, there is a bug in the GAE dev server api.
WooYek