I'm trying to use AWS Api to set the content type of multiple objects and to add a 'content-encoding: gzip' header to them. Here's my code for doing that:
for (S3ObjectSummary summary : objs.getObjectSummaries() )
{
String key = summary.getKey();
if (! key.endsWith(".gz"))
continue;
ObjectMetadata metadata = new ObjectMetadata();
metadata.addUserMetadata("Content-Encoding", "gzip");
metadata.addUserMetadata("Content-Type", "application/x-gzip");
final CopyObjectRequest request = new CopyObjectRequest(bucket, key, bucket, key)
.withSourceBucketName( bucket )
.withSourceKey(key)
.withNewObjectMetadata(metadata);
s3.copyObject(request);
}
When I run this however, the following is the result:
As you can see, the prefix x-amz-meta
was added to my custom headers, and they were lower cased. And the content-type
header was ignored, instead it put www/form-encoded
as the header.
What can I do it to cause it to accept my header values?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With