Albert Still
Albert Still

Reputation: 1009

Change the default content type on multiple files that have been uploaded to a AWS S3 bucket

Using aws-cli I uploaded 5gb of files to an Amazon S3 bucket that I have made a static website. Some of the files the site references are .shtml files, but S3 has defaulted to a metadata content type of binary/octet-stream but I want those files to have a metadata content-Type of text/html. Otherwise it doesn't work in the browser.

Is there a aws-cli s3api command I can use to change the content type for all files with a .shtml extension?

Upvotes: 5

Views: 6496

Answers (2)

Eli Web-Dev
Eli Web-Dev

Reputation: 126

You can set content type on specific file types like the following.

"aws s3 sync ${BASE_DIR} s3://${BUCKET_NAME} --exclude *.shtml"
"aws s3 sync ${BASE_DIR} s3://${BUCKET_NAME} --exclude '*' --include '*.shtml' --no-guess-mime-type --content-type text/html"

Upvotes: 11

John Rotenstein
John Rotenstein

Reputation: 269480

To modify the metadata on an Amazon S3 object, copy the object to itself and specify the metadata.

From StackOverflow: How can I change the content-type of an object using aws cli?:

$ aws s3api copy-object --bucket archive --content-type "application/rss+xml" \
    --copy-source archive/test/test.html --key test/test.html \
    --metadata-directive "REPLACE"

Upvotes: 3

Related Questions