【问题标题】:AccessDenied Invalid according to Policy: Policy Condition failed: ["eq", "$success_action_redirect", "http://localhost/"]AccessDenied 根据策略无效:策略条件失败:[“eq”、“$success_action_redirect”、“http://localhost/”]
【发布时间】:2014-05-23 18:54:47
【问题描述】:

我正在尝试将图像上传到 Amazon S3 存储桶,但收到如下错误,

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Invalid according to Policy: Policy Condition failed: ["eq", "$success_action_redirect", "LOCALHOST"]</Message>

这是我的政策:

POLICY_JSON = {'expiration': '20020-01-01T00:00:00Z',    'conditions': [    {'bucket': 'S3-bucket'},    ['starts-with', '$key', 'uploads/${filename}'],    {'acl': 'private'},    {'success_action_redirect': 'LOCALHOST'},    ['starts-with', '$Content-Type', ' '],    ['content-length-range', 0, 1048576]    ]    };

谁能帮帮我?我该如何解决这个问题?

【问题讨论】:

    标签: javascript amazon-s3 localhost image-uploading image-upload


    【解决方案1】:

    不确定这是否相关,但我发现您的政策存在语法错误。我试过http://www.jsoneditoronline.org/

    在您的政策中,我必须将所有 ' 替换为 ",然后我才能正常验证。

    所以这是将' 替换为" 后的策略

    {"expiration":"20020-01-01T00:00:00Z","conditions":[{"bucket":"S3-bucket"},["starts-with","$key","uploads/${filename}"],{"acl":"private"},{"success_action_redirect":"LOCALHOST"},["starts-with","$Content-Type"," "],["content-length-range",0,1048576]]}
    

    或带缩进:

    {
      "expiration": "20020-01-01T00:00:00Z",
      "conditions": [
        {
          "bucket": "S3-bucket"
        },
        [
          "starts-with",
          "$key",
          "uploads/${filename}"
        ],
        {
          "acl": "private"
        },
        {
          "success_action_redirect": "LOCALHOST"
        },
        [
          "starts-with",
          "$Content-Type",
          " "
        ],
        [
          "content-length-range",
          0,
          1048576
        ]
      ]
    }
    

    【讨论】:

    • 谢谢 slayedbylucifer...它现在可以正常工作,实际上是因为 CORS 我在我的 chrome 中禁用了网络安全,所以工作良好..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-29
    • 2019-09-03
    • 1970-01-01
    • 2013-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多