【发布时间】:2015-06-21 00:20:28
【问题描述】:
我正在尝试设置 S3 静态网站托管,但它似乎在我的任何没有在 AWS 控制台中设置 Content-Type 元数据字段的对象上返回 403。我不知道如何使用 AWS CLI 工具执行此操作。
使用--metadata 选项似乎有效:
$ aws s3api put-object --bucket <bucket> --key foo.html --body foo.html --metadata Content-Type=text/html
{
"ETag": "\"fd5ff7743e5ed1e1c304eb1c34e8e39f\""
}
$ aws s3api head-object --bucket <bucket> --key foo.html
{
"AcceptRanges": "bytes",
"ContentType": "binary/octet-stream",
"LastModified": "Wed, 15 Apr 2015 06:39:48 GMT",
"ContentLength": 189,
"ETag": "\"fd5ff7743e5ed1e1c304eb1c34e8e39f\"",
"Metadata": {
"content-type": "text/html"
}
}
但对象上的 Content-Type 字段在 AWS 控制台的“元数据”部分中不可见,当我尝试在浏览器中访问该文件时收到 403。
使用--content-type 选项也不起作用:
$ aws s3api put-object --bucket <bucket> --key foo.html --body foo.html --content-type text/html
{
"ETag": "\"fd5ff7743e5ed1e1c304eb1c34e8e39f\""
}
$ aws s3api head-object --bucket <bucket> --key foo.html
{
"AcceptRanges": "bytes",
"ContentType": "text/html",
"LastModified": "Wed, 15 Apr 2015 06:46:49 GMT",
"ContentLength": 189,
"ETag": "\"fd5ff7743e5ed1e1c304eb1c34e8e39f\"",
"Metadata": {}
}
虽然它似乎设置了某种特殊的 ContentType 属性,但 AWS 控制台中仍然没有 Content-Type 元数据字段,我也无法在浏览器中访问该文件。
我也尝试过类似的命令(aws s3 cp、aws s3 sync),但没有成功。我已将存储桶策略设置为公开可读。
【问题讨论】:
标签: amazon-web-services amazon-s3 aws-cli