我正在尝试将图片上传到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] ] };
任何人都可以帮助我吗?我该如何解决这个问题?
答案 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
]
]
}