How to set the content type of an S3 object via the SDK?
In SDK V2, use:
PutObjectRequest.builder()
...
.contentType(contentType)
.build()
Found the problem. ObjectMetadata
requires the content-type / encoding to be set explicitly rather than via addUserMetadata()
. Changing the following:
metadata.addUserMetadata("Content-Encoding", "gzip");
metadata.addUserMetadata("Content-Type", "application/x-gzip");
to:
metadata.setContentEncoding("gzip");
metadata.setContentType("application/x-gzip");
fixed this.