我在android中使用transferutility mehtod从亚马逊s3桶下载图像。上传工作正常。但是在下载过程中,当我使用相同的密钥将图像放入存储桶时,会出现错误。
E/error: com.amazonaws.services.s3.model.AmazonS3Exception: The specified key does not exist. (Service: Amazon S3; Status Code: 404; Error Code: NoSuchKey; Request ID: D1B5ACBA8389A6), S3 Extended Request ID: RnoeOgB1TC2AY7AZ+TiMK6C49yUpBcebX2wV0CA6Zy2kl20MTzq+Odo+PLLiBN4a=
我下载图片的代码是:
credentialsProvider();
TransferUtility transferUtility = new TransferUtility(s3Client, getApplicationContext());
file = new File(Environment.getExternalStorageDirectory().toString() + "/" + test_object.getImagesQuestions().get(i).getImageKey());
test_object.getImagesQuestions().get(i).setImage(file);
TransferObserver observer = transferUtility.download(
"BucketName", /* The bucket to upload to */
test_object.getImagesQuestions().get(i).getImageKey(), /* The key for the uploaded object */
test_object.getImagesQuestions().get(i).getImage() /* The file where the data to upload exists */
);
transferObserverListener(observer);
答案 0 :(得分:0)
我发现了问题。实际上从s3下载了多个图像。之后,下载功能执行它在后台运行,直到所有图像下载。我有一个前面的代码,在imageview中设置图像。所以问题是图像还没有下载,而且之前运行的代码也在运行。这就是为什么我没有得到任何图像。