Replies: 1 comment 1 reply
-
|
You can do this, but S3 requires a COPY for “metadata edits”, and when you use a REPLACE-style copy you must explicitly preserve any headers you don’t want to change (especially Content-Type). If you don’t, S3/CLI may fall back to The most reliable approach is to use Example (bash/macOS/Linux): BUCKET="my-bucket" CT=$(aws s3api head-object --bucket "$BUCKET" --key "$KEY" --query ContentType --output text) aws s3api copy-object Why this works S3 only changes metadata via a COPY operation. Notes If the object also uses other important headers (ContentDisposition, ContentEncoding, StorageClass, SSE-KMS, etc.), you must preserve those the same way (fetch via |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Goal: I want to change the
Cache-Controlkey to some value from its existing, egmax-age=xyz, without touching anything else, and esp without having Content-Type getting screwed.Something so simple cannot be performed on the aws console, this used to be allowed earlier, but now one needs to go thru some convoluted copy step (https://docs.aws.amazon.com/AmazonS3/latest/userguide/add-object-metadata.html). Anyway - the net result of that is that the
Content-Typeturns tobinary/octet-streamfromimage/jpegor whatever after copy.Fine, I thought this was an issue only on the console, and turned to the CLI. (The AWS userguide links to v1 of the CLI docs, while the current version is v2 - which leads to still more headache)
The v2 CLI is equally unhelpful - there is no adequate documentation as given here https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/cp.html
The earlier
--metadata-directive REPLACEhas been removed and there is a new--copy-props. However its quite unclear how to use this to change a single metadata while leaving everything else the same. I cannot imagine that this is some complex usecase - why is this simple thing not supported? If it is supported - where is the helpful documentation around it?Beta Was this translation helpful? Give feedback.
All reactions