我使用下面的代码来获取存储桶中的对象。 我期待一个空的响应,但代码在这里抛出异常。
final ListObjectsRequest listObjectRequest = new ListObjectsRequest().withBucketName(s3Bucket)
.withMaxKeys(1).withPrefix(prefix);
final ObjectListing objectListing = s3client.listObjects(listObjectRequest);
参数: s3_bucket => “my-bucket / incoming /”和prefix => “PRE _”
例外:
com.amazonaws.services.s3.model.AmazonS3Exception: The specified key does not exist. (Service: Amazon S3; Status Code: 404; Error Code: NoSuchKey; Request ID: BF85E6E0CF00717E)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1181) ~[aws-java-sdk-core-1.10.24.jar:?]
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:766) ~[aws-java-sdk-core-1.10.24.jar:?]
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:485) ~[aws-java-sdk-core-1.10.24.jar:?]
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:306) ~[aws-java-sdk-core-1.10.24.jar:?]
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3604) ~[aws-java-sdk-s3-1.10.24.jar:?]
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3557) ~[aws-java-sdk-s3-1.10.24.jar:?]
at com.amazonaws.services.s3.AmazonS3Client.listObjects(AmazonS3Client.java:647) ~[aws-java-sdk-s3-1.10.24.jar:?]