简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM