You can use the below set of code , which is a aynctask which will use glide to attach private images from s3 by generating presignedurl.
public class sets3imageasync extends AsyncTask {
// The list of objects we find in the S3 bucket
static final String s3bucket=bucket_name;
Context scontext;
ImageView image;
@Override
protected String doInBackground(Object... objects) {
// Queries files in the bucket from S3.
Calendar cal = Calendar.getInstance();
Log.d(TAG, "doInBackground: in progress");
cal.setTime(new Date());
cal.add(Calendar.HOUR, +1);
Date oneHourLater = cal.getTime();
AmazonS3Client s3 = (AmazonS3Client) objects[0];
scontext= (Context) objects[1];
image=(ImageView) objects[2];
String imagekey=(String) objects[3];
GeneratePresignedUrlRequest generatePresignedUrlRequest =
new GeneratePresignedUrlRequest(s3bucket, imagekey)
.withMethod(HttpMethod.GET)
.withExpiration(oneHourLater);
URL url = s3.generatePresignedUrl(generatePresignedUrlRequest);
Log.e("url was", url.toString());
return url.toString();
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
Log.d(TAG, "onPostExecute: completed "+s);
Glide.with(scontext).load(s)
.apply(new RequestOptions()
.centerCrop())
.placeholder(scontext.getResources().getDrawable(R.drawable.progress_animation))
.into((image));
}
this can be called as below
new sets3imageasync().execute(s3Client,context,Image_view);