首页 > 解决方案 > AWS S3-策略条件失败-eq 键

问题描述

我正在从网站上传文件到 s3。我从使用aws sdk. 我遇到的问题是它生成了一个我必须在我的表单中使用的密钥,如下所示:

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

它有效,但我上传的每个文件都有“密钥”的名称。如果我把它改成这样:

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

它给了我一个错误:

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

以下是我生成策略的条件:

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

如何设置文件的名称?

标签: htmlnode.jsamazon-web-servicesamazon-s3

解决方案


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


推荐阅读