问题
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.
回答1:
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());
来源:https://stackoverflow.com/questions/56949135/check-metadata-of-s3-objects-with-aws-sdk-for-java-2-x