【问题标题】:Change the default content type on multiple files that have been uploaded to a AWS S3 bucket更改已上传到 AWS S3 存储桶的多个文件的默认内容类型
【发布时间】:2015-08-13 11:11:53
【问题描述】:

我使用 aws-cli 将 5gb 的文件上传到了我制作的静态网站的 Amazon S3 存储桶中。站点引用的一些文件是 .shtml 文件,但 S3 默认的元数据内容类型为 binary/octet-stream,但我希望这些文件的元数据内容类型为 text/html。否则在浏览器中不起作用。

是否有一个 aws-cli s3api 命令可用于更改所有扩展名为 .shtml 的文件的内容类型?

【问题讨论】:

    标签: amazon-s3 aws-cli


    【解决方案1】:

    您可以为特定文件类型设置内容类型,如下所示。

    "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"
    

    【讨论】:

    • 为什么第一行提到.svg?
    • BASE_DIR 指的是什么?
    • 更新为与 OP 的问题相关。 BASE_DIR 将是您文件的位置。
    【解决方案2】:

    要修改 Amazon S3 对象的元数据,将对象复制到自身并指定元数据。

    来自 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"
    

    【讨论】:

      猜你喜欢
      • 2015-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-25
      • 1970-01-01
      • 2018-08-31
      • 2021-02-07
      • 2017-09-17
      相关资源
      最近更新 更多