Search code examples
amazon-s3aws-java-sdkaws-java-sdk-2.x

AWS SDK Java version 2 - is there an equivalent to doesObjectExist() from ver 1?


The S3 client in the AWS Java SDK ver 1 had a method to check for the existence of an object in a bucket

doesObjectExist(bucketName, objectName)

In version 2 of the SDK I don't see anything similar but I wanted to see if I was missing anything.

The only idea I had was to attempt to use

S3Client.getObject(GetObjectRequest) which will throw a NoSuchKeyExcecption if the object doesn't exist. I hate to use an exception like this.


Solution

  • please see s3 client service changes - https://github.com/aws/aws-sdk-java-v2/blob/master/docs/LaunchChangelog.md#4-service-changes

    headObject is the 2.0 equivalent operation