5

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?

Albert Still
  • 989
  • 9
  • 17

2 Answers2

11

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"
Eli Web-Dev
  • 126
  • 1
  • 5
3

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"
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470