我尝试将图像上传到 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] ] };
有人可以帮助我吗?我该如何解决这个问题?
最佳答案
不确定这是否相关,但我发现您的策略有语法错误。我在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
]
]
}
关于javascript - AccessDenied 根据策略 : Policy Condition failed: ["eq", "$success_action_redirect"、 "http://localhost/"无效],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22981741/