Reputation: 4712
I was not able to find a way to check the metadata fields of an S3 object such as the Content-Type
or the Cache-Control
with the AWS SDK for Java 2.x.
With the AWS SDK for Java 1.x it was as easy as this:
s3Client.getObjectMetadata("myBucket", "myfile.doc");
But I cannot see the analogous method for the newest version of the API.
Upvotes: 14
Views: 9586
Reputation: 156
Also relevant, you can get additional metadata using getObjectAttributes
, which for AWS S3 Java 2.x SDK is used in place of getObjectMetadata
.
Upvotes: 1
Reputation: 4712
The solution is to use HeadObjectRequest
and HeadObjectResponse
:
HeadObjectRequest headObjectRequest = HeadObjectRequest.builder()
.bucket(bucketName)
.key(key)
.build();
And then:
HeadObjectResponse headObjectResponse = s3Client.headObject(headObjectRequest);
System.out.println("This is what I need: " + headObjectResponse.contentType());
Upvotes: 20