AccessDenied Invalid according to Policy: Policy Condition failed: ["eq", "$success_action_redirect", "http://localhost/"]

StackOverflow https://stackoverflow.com/questions/22981741

Question

I'm trying to upload image to Amazon S3 bucket but getting a error like,

<?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>

This is my policy:

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]    ]    };

Can anyone help me? How can i fix this problem?

Was it helpful?

Solution

Not sure whether this is relevant, But I could find that your policy has syntax error. I tried it on http://www.jsoneditoronline.org/

In your policy, I had to replace all the ' with " and then I was able to validate it fine.

So here is the policy after replacing ' with "

{"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]]}

OR with indentation:

{
  "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
    ]
  ]
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top