从Amazon S3下载图像时如何使用Picasso库? [英] How do use use Picasso library while downloading images from Amazon S3?
本文介绍了从Amazon S3下载图像时如何使用Picasso库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将图像存储在Amazon S3上.我使用以下代码从Amazon S3下载图像
I am storing my images on Amazon S3. I use the following code to download image from Amazon S3
S3ObjectInputStream content = s3Client.getObject("bucketname", url).getObjectContent();
byte[] bytes ;
bytes = IOUtils.toByteArray(content);
bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
bitmap = CommonUtilities.getRoundedCornerBitmap(bitmap, 30);
cache.put(url, new SoftReference<Bitmap>(bitmap));
return bitmap;
在阅读毕加索文档时,我读到了加载我们只需要做的图像
While going through Picasso documentation, I read that to load images we simply need to do
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
那么如何通过毕加索下载Amazon S3图像.
So how to download Amazon S3 images through Picasso.
推荐答案
您可以使用使用适用于Java的AWS开发工具包生成预签名对象URL ".尽管该示例适用于Java SDK,但适用于AWS Android SDK.
You can use AmazonS3.generatePresignedUrl(String, String, Date)
to generate a presigned url and pass it to Picasso. Here is an example "Generate a Pre-signed Object URL using AWS SDK for Java". Though the example is for the Java SDK, it's applicable for the AWS Android SDK.
这篇关于从Amazon S3下载图像时如何使用Picasso库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文