0

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
    else:        
        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:

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

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

DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
    .cacheInMemory()
    .cacheOnDisc()
    .build();

ImageLoaderConfiguration config = new ImageLoaderConfiguration
    .Builder(getApplicationContext())
    .defaultDisplayImageOptions(defaultOptions).build();

ImageLoader.getInstance().init(config);

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?

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
Miki
  • 1,625
  • 21
  • 29
  • Suggestion: Hit both URLs from a browser that has good debugging tools (e.g., Chrome, or Firefox with Firebug), and compare the response headers. Something might jump out. – Dave W. Smith Mar 28 '13 at 16:00
  • Thanks Dave. Great advice. I've added a couple of attributes to the header just in case: response['Accept-Ranges'] = 'bytes' response['Cache-Control'] = 'max-age=86400' The headers look pretty similar now: – Miki Mar 28 '13 at 18:20
  • Just updated the question above with the headers information. – Miki Mar 28 '13 at 18:33
  • Can you provide link to image on Google DataStore? Or share image from DataStore as it there. It seems DataStore keeps some compressed image (less size), maybe this specified compression prevent image decoding by Android (so you see `--- SkImageDecoder::Factory returned null `). – nostra13 Mar 28 '13 at 19:57
  • Can you try to update to 1.8.2? – nostra13 Mar 29 '13 at 21:50
  • V1.8.2 makes the trick. Can you add an answer so I can accept it? – Miki Mar 29 '13 at 23:47

1 Answers1

1

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.

nostra13
  • 12,377
  • 3
  • 33
  • 43
  • This did not work with me in ver 1.9.x of UIL when loading content:// images (contact photos) – Sarang May 27 '15 at 10:46