问题
so I want to be able to grab my images from my s3 bucket and (using glide or picasso) load that image into an imageview. (I don't want to download that image into my phone).
currently i have this:
downloadButton = (Button) findViewById(R.id.cognito_s3DownloadButton);
downloadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
File file = new File(Environment.getExternalStorageDirectory().toString() + "/" + "fromAWS");
observer = transferUtility.download("zivit-card-images","image1", file);
Glide.with(getBaseContext()).load("image in byes? or url?").centerCrop().into(myImageView);
}
});
Again, how do i retrieve the image from s3 and insert it into an imageview?
回答1:
When using Glide or Picasso, you need not worry about the location where the image
will be saved. Picasso or Glide takes care of the Caching
so that you don't have to.
Now, all you need to set an Image to an ImageView using Glide or Picasso is an image URL
. I think you want to use an image from your S3 bucket, then you need to have an image from your S3 bucket, something like this:
https://a2.muscache.com/im/pictures/9c66dcc5-6d39-43b3-82ec-72e9d119f873.jpg
then all you need to do with your code is:
downloadButton = (Button) findViewById(R.id.cognito_s3DownloadButton);
downloadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Glide.with(getBaseContext())
.load("https://a2.muscache.com/im/pictures/9c66dcc5-6d39-43b3-82ec-72e9d119f873.jpg")
.centerCrop()
.into(myImageView);
}
});
回答2:
public String downloadimage()
{
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.HOUR, +1);
Date oneHourLater = cal.getTime();
AmazonS3 s3 = new AmazonS3Client(credentialsProvider);
URL url = s3.generatePresignedUrl(
"testproject12345",
"first.jpg",
oneHourLater
);
Log.e("url was", url.toString());
String urlstring = url.toString();
return urlstring;
}
catch that function in your activity
download = (Button)findViewById(R.id.download);
final ImageView imageview = (ImageView) findViewById(R.id.image);
download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
download1 = new Uploader(getmain().getCredentialsProvider(),getApplicationContext());
String url = download1.downloadimage();
Picasso.with(getApplicationContext())
.load(url)
.into(imageview);
}
});
来源:https://stackoverflow.com/questions/41404527/how-to-download-image-from-aws-s3-into-imageview