本文介绍了在S3 Client android中制作私有图像的ImageGallery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的Android应用程序中创建我的S3 Bucket的imageGallery。我的图像是私有的,所以我不会为每个图像提供任何特定的链接。

I am trying to create an imageGallery of my S3 Bucket in my android application. My images are private so i won't be having any specific link for each image.

对于此类私人图片,亚马逊有一个链接生成器,

For Such private images , amazon has a link generator,

s3Client.generatePresignedUrl(Constants.S3_BUCKET_NAME, key, expiration);

它生成一个URL,假设我们设置了1小时或2分钟到期。

It generates a URL with let's say 1 hour or 2 min expiration set by us.

现在为了简单的内存缓存和内容,我可以使用volley或Picasso或许多其他类似的轻松加载库。

Now for easy memory caching and stuff, i can either use volley or Picasso or many other such easy loading libraries.

但是有这个问题。我想将这些图像缓存在内存中。但我所拥有的只是动态链接。

However there is this catch. I want to cache these images in memory. But all i have is dynamic link.

如何让Picasso或任何其他图书馆使用动态链接进行缓存?

How can i make Picasso or any other library use dynamic link to cache?

根据我的信息,这些库使用Url作为缓存的密钥,是对吗?如果是这样我怎么能保存这些图像所以我可以稍后使用这些图像,即使我离线,再次,我有动态链接所以url将每时刻都在改变所以也许我需要用Key保存它们我传递给s3Client。

As per my information, the libraries use Url as "key" to cache, is that correcT? if so how can i save these images so i can use these images later even when i am offline, again, i have dynamic link so url will be changing every instant so maybe i need to save them with the Key i am passing to s3Client.

解决方案是什么。

推荐答案

最新 Picasso 版本采用设置网络策略。可能需要为 Picasso.Request 构建器设置 NetworkPolicy.OFFLINE

Latest Picasso version adopts setting network policies. Probably, you need to set NetworkPolicy.OFFLINE for the Picasso.Request builder:

Picasso.with(this)
            .load(s3Url)
            .networkPolicy(NetworkPolicy.OFFLINE)
            .into(imageView);

关于缓存,您可能希望将到期时间设置为 CacheControl OkHttpClient 的code>,与S3链接相同。

Regarding the caching, you might want to set expiration time to CacheControl of the Picasso OkHttpClient, to be same as the S3 links.

这篇关于在S3 Client android中制作私有图像的ImageGallery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 02:33