Miki Miki - 1 month ago 8x
Android Question

Universal Image Loader fails when retrieving images served by Google Data Store

My GAE instance serves images stored in Google Data Store:

def serveAvatarByName(request,username):
entity_list = Entity.gql("WHERE username = :1", username)
entity = entity_list.get()

if entity:
image_data = entity.image
response = HttpResponse(image_data)

response['Content-Type'] = entity.content_type
image_data = open("static/img/anonymous.png", "rb").read()
response = HttpResponse(image_data)

response['Content-Type'] = 'image/png'

response['Accept-Ranges'] = 'bytes'
response['Cache-Control'] = 'max-age=86400'
return response

My image URIs typically look like this:


My Android client gets these images using the fantastic Sergey Tarasevich's Universal Image Loader, configured as below:

DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()

ImageLoaderConfiguration config = new ImageLoaderConfiguration


And retrieves them:

String imageUri1 = "http://my-app.appspot.com/serve_avatar/user1.png";
//String imageUri2 = "http://xpda.com/junkmail/junk207/jpgcompressionb1.png";

ImageLoader.getInstance().displayImage(imageUri1, imageView);

The first image (imageUri1) is a PNG stored in my Google Data Store instance and is shown correctly in a browser pointing to imageUri1, but UIL fails, showing the following message in the log:

03-28 10:41:37.093: D/skia(25780): --- SkImageDecoder::Factory returned null

If I implement the onLoadingFailed method and print the "failReason" I get "IO_ERROR", but nothing else.

If the user has no avatar image uploaded yet, a default picture (anonymous.png) is served instead. That does not work either.

Notice that UIL works correctly when accessing the second image (imageUri2, a png file).

The headers look look like this:

imageUri1 - http://my-app.appspot.com/serve_avatar/user1.png:

HTTP request status: 200 (OK)

Date Thu, 28 Mar 2013 18:05:46 GMT
Cache-Control max-age=86400
Server Google Frontend
Accept-Ranges bytes
Content-Length 41686
Vary Cookie
Content-Type image/png

imageUri2 - http://xpda.com/junkmail/junk207/jpgcompressionb1.PNG:

HTTP request status: 200 (OK)

Date Thu, 28 Mar 2013 14:14:58 GMT
ETag "5de35c2e5eeca1:0"
Last-Modified Sat, 08 May 2010 19:36:30 GMT
Server Microsoft-IIS/7.0
X-Powered-By ASP.NET
Content-Type image/png
Cache-Control max-age=86400
Accept-Ranges bytes
Content-Length 535279

Any idea what could be wrong?


UIL uses FlushedInputStream prior to 1.8.2 for image downloading (http://code.google.com/p/android/issues/detail?id=6066). It can be a reason of your problem. Since 1.8.2 FlushedInputStream isn't used by default but it can be enabled by ImageLoader.handleSlowNetwork(true).

So try to update to 1.8.2.