【问题标题】:Universal Image Loader fails when retrieving images served by Google Data Store检索 Google Data Store 提供的图像时,通用图像加载器失败
【发布时间】:2013-03-28 15:13:02
【问题描述】:

我的 GAE 实例提供存储在 Google 数据存储中的图像:

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    

我的图像 URI 通常如下所示:

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

我的 Android 客户端使用出色的 Sergey Tarasevich 的通用图像加载器获取这些图像,配置如下:

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

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

ImageLoader.getInstance().init(config);

并检索它们:

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);

第一个图像 (imageUri1) 是存储在我的 Google 数据存储实例中的 PNG,在指向 imageUri1 的浏览器中正确显示,但 UIL 失败,在日志中显示以下消息:

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

如果我实现 onLoadingFailed 方法并打印“failReason”,我会得到“IO_ERROR”,但没有别的。

如果用户尚未上传头像图片,则会提供默认图片 (anonymous.png)。那也不行。

请注意,当访问第二张图片(imageUri2,一个 png 文件)时,UIL 可以正常工作。

标题如下所示:

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

知道可能出了什么问题吗?

【问题讨论】:

  • 建议:从具有良好调试工具的浏览器(例如,Chrome 或带有 Firebug 的 Firefox)中点击两个 URL,并比较响应标头。有些东西可能会跳出来。
  • 谢谢戴夫。很好的建议。为了以防万一,我在标题中添加了几个属性: response['Accept-Ranges'] = 'bytes' response['Cache-Control'] = 'max-age=86400' 现在标题看起来非常相似:
  • 刚刚用标题信息更新了上面的问题。
  • 您能否提供指向 Google DataStore 上图像的链接?或者在那里共享来自 DataStore 的图像。似乎 DataStore 保留了一些压缩图像(较小的大小),也许这种指定的压缩会阻止 Android 对图像进行解码(所以你看--- SkImageDecoder::Factory returned null )。
  • 可以尝试更新到 1.8.2 吗?

标签: android google-app-engine mime-types google-cloud-datastore universal-image-loader


【解决方案1】:

UIL 使用FlushedInputStream 1.8.2 之前的版本 进行图像下载 (http://code.google.com/p/android/issues/detail?id=6066)。这可能是您的问题的原因。由于 1.8.2 默认不使用FlushedInputStream,但可以通过ImageLoader.handleSlowNetwork(true) 启用。

所以尝试更新到 1.8.2

【讨论】:

  • 在加载 content:// 图像(联系人照片)时,这在 UIL 的 1.9.x 版本中不适用于我
猜你喜欢
  • 2014-08-31
  • 2012-12-03
  • 2015-01-13
  • 2013-06-15
  • 2016-07-17
  • 2013-05-12
  • 1970-01-01
  • 1970-01-01
  • 2017-04-07
相关资源
最近更新 更多