2

所以我希望能够从我的S3存储抢我的图片和(使用滑行或毕加索),其图像加载到ImageView的。 (我不想将该图像下载到我的手机中)。如何将图片从aws s3下载到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的?

+0

您传递文件参考'transferUtility.download()',那该文件到传输工具将在S3对象下载到。 – Karthik

回答

1

使用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); 
     } 
}); 
+0

从TransferObserver对象,我怎么抢图片的网址?一般来说,获取图像s3网址的方法是什么?你能否把它包含在你的代码中? –

+1

对不起,我没有S3的经验,你需要自己处理S3的东西,但是,S3图片的URL应该像其他图片的URL一样,所以下面的代码也适用于S3图片。 –

+0

是的,那很好,那很好。欣赏回应 –

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); 


      } 
     });