AWS S3-策略条件失败-eq密钥 [英] AWS S3- Policy Condition Failed- eq key
问题描述
我正在从网站上将文件上传到s3.我从使用aws sdk
的nodejs服务器中获取了所有需要的信息.我的问题是它生成了一个密钥,必须在我的表单中使用它,如下所示:
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 />
它给我一个错误:
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"}
]
如何设置文件名?
推荐答案
我解决了.问题是在传递此函数的参数对象中:
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
这篇关于AWS S3-策略条件失败-eq密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!