目的:尝试显示存储在AWS中的图像。上拉/下拉12个图像将显示在GridView中。我可以使用以下方式下载图像:
try {
InputStream in = new java.net.URL(url).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
bmImage.setImageBitmap(mIcon11);
这意味着网址有效。但是,问题是当我将URL传递给Image Loader时,它会显示以下错误:(我将url中的键和其他内容替换为'something'。)
05-13 10:29:40.437 14053-14160/com.example.test E/ImageLoader﹕ https://s3.amazonaws.com/test/photo/1405.jpg?AWSAccessKeyId=something& something = something&Signature= something
java.io.FileNotFoundException: https://s3.amazonaws.com/test/photo/1405.jpg?AWSAccessKeyId=something& something = something&Signature= something
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:197)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25)
at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromNetwork(BaseImageDownloader.java:122)
at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(BaseImageDownloader.java:86)
at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.getImageStream(BaseImageDecoder.java:93)
at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.decode(BaseImageDecoder.java:73)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(LoadAndDisplayImageTask.java:264)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:237)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:135)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
如何使用Image Loader下载aws url?或者还有其他更好的方式来显示来自aws的12个或更多图像吗?谁知道?非常感谢你!
答案 0 :(得分:1)
要从AWS S3存储桶下载图像,您需要使用AmazonS3客户端。然后使用awskey和aws密钥,您可以使用以下代码下载任何图像。
Resources res = mContext.getResources();
String awsKey = res.getString(R.string.aws_key);
String awsSecretKey = res.getString(R.string.aws_secret_key);
String awsBucketName = res.getString(R.string.aws_bucket_name);
AmazonS3Client s3Client = new AmazonS3Client(
new BasicAWSCredentials(mContext.getResources().getString(R.string.aws_key),
mContext.getResources().getString(R.string.aws_secret_key)));
S3ObjectInputStream content = s3Client.getObject(awsBucketName, url).getObjectContent();