AccessDenied根据策略无效:策略条件失败:[" eq"," $ success_action_redirect"," http:// localhost /"]

时间:2014-04-10 07:43:27

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

我正在尝试将图片上传到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]    ]    };

任何人都可以帮助我吗?我该如何解决这个问题?

1 个答案:

答案 0 :(得分: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
    ]
  ]
}