I'm updating existing objects in an Amazon S3 bucket to set some metadata. I'd like to set the HTTP Expires
header for each object to better handle HTTP/1.0 clients.
We're using the AWS Java SDK, which allows for metadata changes to an object without re-uploading the object content. We do this using CopyObjectRequest to copy an object to itself. The ObjectMetadata class allows us to set the Cache-Control
, Content-Type
and several other headers. But not the Expires
header.
I know that S3 stores and serves the Expires
header for objects PUT using the REST API. Is there a way to do this from the Java SDK?
Updated to indicate that we are using CopyObjectRequest
Best Answer
To change the metadata of an existing Amazon S3 object, you need to copy the object to itself and provide the desired new metadata on the fly, see copyObject():
This can be achieved like so approximately (fragment from the top of my head, so beware):
Please be aware of the following easy to miss, but important copyObject() constraint:
This is not accounted for in my code fragment yet!
Good luck!