8888
8888

Reputation: 2064

Add content-disposition metadata when uploading to s3 using the cli

Using the AWS CLI, how do I upload a file and specify a value for the Content-Disposition response header? Through the console, this header can be created by adding it as metadata, but a CLI command will allow this to be part of a CI pipeline.

Content-Disposition response header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition

Upvotes: 2

Views: 1850

Answers (1)

8888
8888

Reputation: 2064

The aws cli command cp has an optional argument --content-disposition that makes this possible. --content-dispostion can either be set as attachment or inline.

aws s3 cp <src> <dest> --content-disposition attachment

This works for setting the metadata when it is uploaded, but if you later copy this file to a different path in s3, the metadata will not persist. To allow it to persist, you need to explicitly set this at upload time with the --metadata-directive REPLACE argument. The final command I use is:

aws s3 cp <src> <dest> --metadata-directive REPLACE --content-disposition attachment

aws s3 cp documentation: https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html

Upvotes: 3

Related Questions