Reputation: 137
In AmazonS3Client
there is a method doesObjectExist(String bucketName, String objectName)
. This method throws an com.amazonaws.services.s3.model.AmazonS3Exception: Bad Request (Service: Amazon S3; Status Code: 400; Error Code: 400 Bad Request;
if you are calling it for an encrypted object. Any other way to check if an object exists, without knowing the encryption key that was used when saving it? I do not want to access the object without having the encryption key, I just want to know if an object named 'blabla' exists or not, so I can prompt an error message to a client that wants to upload an object called 'blabla'.
Upvotes: 0
Views: 1443
Reputation: 53713
You could list all elements within the bucket and check if your object is there. even better with the withPrefix
method you can limit the response
http://docs.aws.amazon.com/AmazonS3/latest/dev/ListingObjectKeysUsingJava.html
ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
.withBucketName(bucketName)
.withPrefix("blabla");
You can also look at getObjectSummaries()
method to know more about the returned object
Upvotes: 2