Skip to content Skip to sidebar Skip to footer

How Do Use Use Picasso Library While Downloading Images From 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

Solution 1:

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.

Solution 2:

You are getting the InputStream of the S3Object, which will give bytes representation of that object. Instead, you need to build URI from to the S3Object. As far as I know the url is build in following manner:

S3_END_POINT + bucket + key.

Check the use of S3Object redirect location (S3 gives different endpoint url, depending on your location)

Therefore:

StringS3_END_POINT="https://s3.amazonaws.com/"; // public filesS3Objects3Object= s3Client.getObject("bucketname", url);
Stringurl= S3_END_POINT + s3Object.getBucketName() + SLASH + s3Object.getKey();
Picasso.with(context).load(url).into(imageView);

Post a Comment for "How Do Use Use Picasso Library While Downloading Images From Amazon S3?"