AWS S3 Bucket Policy无法在移动浏览器上运行

时间:2018-03-01 15:03:45

标签: image amazon-web-services mobile amazon-s3

我的问题如下: 我在heroku上部署了一个网站,并使用“AWS S3 Bucket”进行图像托管。我添加了一个存储桶策略,因此图像只能在被referrer调用时加载,这是我的域名。它适用于所有桌面浏览器,但如果我从iPhone打开带有Safari或Chrome的页面,则无法加载图像。 我的存储桶政策如下:

{
"Version": "2012-10-17",
"Id": "diearch.images bucket Policy",
"Statement": [
    {
        "Sid": "Allow get requests originating from diearch.herokuapp.com.",
        "Effect": "Allow",
        "Principal": "*",
        "Action": "s3:GetObject",
        "Resource": "arn:aws:s3:::diearch-images/*",
        "Condition": {
            "StringLike": {
                "aws:Referer": [
                    "https://diearch.herokuapp.com/*",
                    "diearch.herokuapp.com*"
                ]
            }
        }
    },
    {
        "Sid": "Explicit deny to ensure requests are allowed only from specific referer.",
        "Effect": "Deny",
        "NotPrincipal": {
            "AWS": "arn:aws:iam::123456789:root" //user changed 
        },
        "Action": "s3:*",
        "Resource": "arn:aws:s3:::diearch-images/*",
        "Condition": {
            "StringNotLike": {
                "aws:Referer": [
                    "https://diearch.herokuapp.com/*",
                    "diearch.herokuapp.com/*"
                ]
            }
        }
    }
]}

我的CORS如下:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <CORSRule>
    <AllowedOrigin>https://diearch.herokuapp.com</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedHeader>*</AllowedHeader>
    <AllowedHeader>origin</AllowedHeader>
  </CORSRule>
 </CORSConfiguration>

提前谢谢!

1 个答案:

答案 0 :(得分:0)

该错误并未将http-地址列入白名单。 Safari和移动浏览器未发送https。