the purpose: Trying to show images that store in AWS. When pull up/down 12 images will show in GridView. I could download the images by using:
目的:尝试显示存储在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);
This means the url works. However, the question is when I passing the url to the Image Loader, it show the error below: (I replace the key and other stuff in the url to 'something'.)
这意味着网址有效。但是,问题是当我将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)
How could I download the aws url with Image Loader? Or is there any other better way to showing 12 or more images from aws? Anyone know? Thank you so much!
我怎么能用Image Loader下载aws url?或者还有其他更好的方式来显示来自aws的12个或更多图像吗?谁知道?非常感谢!
1 个解决方案
#1
To download images from AWS S3 bucket, you need to use AmazonS3 Client. Then using the awskey and aws secret key you can download any image using the below code.
要从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();
#1
To download images from AWS S3 bucket, you need to use AmazonS3 Client. Then using the awskey and aws secret key you can download any image using the below code.
要从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();