因此,我希望能够从我的S3存储桶中获取我的图像,然后(使用Glide或Picasso)将图像加载到ImageView中。(我不想将该图像下载到我的手机中)。
目前我有:
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);
}
});
再次,如何从S3中检索图像并将其插入imageView?
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);
}
});
如显示@prog,您必须使用
amazonS3Client!!.generatePresignedUrl({your_bucket_name}, {your_key_image_file}, {expiration_date_of_url})
生成URL比毕加索使用的URL。
但是要小心,您只需要第一次生成URL。将其存储并在未过期的情况下重复使用。每次使用AWS方法生成URL时,响应都是新的URL。因此,您不会在缓存中获得图像,因为他的关联URL是另一个。您将再次进行HTTP调用。
对不起,我的英语,希望是帮助,托马斯
使用Glide或Picasso时,您不必担心将保存image
的位置。毕加索或滑行会照顾Caching
,因此您不必这样做。
现在,您需要使用Glide或Picasso将图像设置为ImageView是图像URL
。我认为您想使用S3存储桶中的图像,然后您需要从S3存储桶中获得图像,类似的东西:
https://a2.muscache.com/im/pictures/9c66dcc5-6d39-43b3-82ec-72e9d119f873.jpg
那么,您需要使用的代码所需要做的就是:
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);
}
});