AWS S3- Policy Condition Failed- eq key

I am working on uploading files to s3 from the website. I get all needed information from my nodejs server which uses aws sdk. The problem I have is that it generates a key which I have to use in my form like this:

   <input type="hidden" name="key" value="xxx" /><br />

And it works, but every file I upload has the name of the 'key'. If I change it to sth like this:

   <input type="hidden" name="key" value="xxx/name.jpg" /><br />

It gives me an error:

Invalid according to Policy: Policy Condition failed: ["eq", "$key", "xxx"]

Here are my conditions to generate the policy:

Conditions: [
        ['starts-with', '$key', ''],
        ["starts-with", "$Content-Type", "image/"],
        {"x-amz-server-side-encryption": "AES256"}
      ]

How can I set the name of the file?

Upvotes: 1

Views: 1519

Answers (1)

I solved it. The problem was that in parameters object which is passed this function:

s3.createPresignedPost(params, function(err, data)

I had parameter Fields which included key:

  Fields: {
    key: key,
  },

Simply deleting it fixed the problem

Upvotes: 1

Related Questions