9

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.

menapole
  • 1,166
  • 1
  • 11
  • 22

1 Answers1

9

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

Suriyakanth
  • 269
  • 4
  • 13
  • but i checked headObject method implementation and it is simply throwing unsupported operation exception. – learner Aug 06 '20 at 15:02
  • You need to check the concrete implementation of the S3Client (usuallly DefaultS3Client). – Basa Nov 22 '21 at 12:28