通过邮政和ASP.NET MVC的Amazon S3上传 [英] Amazon S3 Upload via Post and ASP.NET MVC
问题描述
我一直妄图2天,现在做一个简单的上传到我的Amazon S3的桶。下面是我的呈现形式:
<形式的行动=http://s3.amazonaws.com/MYBUCKETNAME方法=POSTENCTYPE =的multipart / form-data的>
<输入类型=隐藏的名字=AWSAccessKeyIdVALUE =MYACCESSKEY/>
<输入类型=隐藏的名字=ACLVALUE =私有/>
<输入类型=隐藏的名字=键值=UserUploads /为TestUser / $ {文件名}/>
<输入类型=隐藏的名字=success_action_redirectVALUE =http://WWW.MYURL.COM//>
<输入类型=隐藏的名字=政策VALUE =政策/>
<输入类型=隐藏的名字=签名值=签名/>
< DIV>
请指定一个文件或一组文件:
<输入类型=文件名称=文件大小=100/>
< / DIV>
<输入类型=提交值=上传/>
< /表及GT;
和我的政策文件看起来是这样的:
{
期满=2011-12-08T12:00:00.000Z,
条件= [
[EQ,斗,MYBUCKETNAME],
[EQ,ACL,私人]
[开始,以,$键,UserUploads /为TestUser /],
[EQ,success_action_redirect,HTTP://WWW.MYURL.COM/]
]
}
我收到以下错误:
code:存取遭拒,
消息:策略条件失败:根据政策无效[EQ,斗,MYBUCKETNAME]
有没有人有请,我在这里救命稻草抓住任何想法。还不能肯定,如果我的桶政策和ACL是正确的。
根据 http://doc.s3.amazonaws.com/proposals/post.html#Access_Control
匹配一个特定值
说明:有要符合特定领域
特定的值,如匹配水桶名称或要求由
对象是使用公共读访问控制策略上传。该
字段的值是大小写敏感的,但是名字却不是。
语法:有要求的领域字段名匹配两种方式
字符串值。该值是区分大小写的。如果该值开始
以美元符号($),美元符号必须使用转义
反斜线(\\ $)
块引用>[EQ,$字段名,S],
(注意$ preFIX)。
所以,你的政策,你应该使用有$成套EQ的格式
I've been trying in vain for 2 days now to do a simple upload to my Amazon S3 Bucket. Below is my rendered form:
<form action="http://s3.amazonaws.com/MYBUCKETNAME" method="post" enctype="multipart/form-data"> <input type="hidden" name="AWSAccessKeyId" value="MYACCESSKEY" /> <input type="hidden" name="acl" value="private" /> <input type="hidden" name="key" value="UserUploads/TestUser/${filename}" /> <input type="hidden" name="success_action_redirect" value="http://WWW.MYURL.COM/" /> <input type="hidden" name="policy" value="POLICY" /> <input type="hidden" name="signature" value="SIGNATURE" /> <div> Please specify a file, or a set of files: <input type="file" name="file" size="100" /> </div> <input type="submit" value="Upload" /> </form>
and my policy document looks like this:
{ expiration = "2011-12-08T12:00:00.000Z", conditions = [ ["eq","bucket","MYBUCKETNAME"], ["eq","acl","private"], ["starts-with","$key","UserUploads/TestUser/"], ["eq","success_action_redirect", "HTTP://WWW.MYURL.COM/"] ] }
I get the following error: Code: AccessDenied, Message: Invalid according to Policy: Policy Condition failed: ["eq", "bucket", "MYBUCKETNAME"]
Does anyone have any ideas please, I'm grabbing at straws here. Also not sure if my Bucket Policy and ACL is correct.
解决方案According to http://doc.s3.amazonaws.com/proposals/post.html#Access_Control
Matching a Particular Value
Description: There are certain fields that you want to match a particular value, such as matching a bucket name or requiring that an object is uploaded using the public-read access control policy. The field value is case sensitive, but the name is not.
Syntax: There are two ways to require that the field fieldname matches the string value. The value is case sensitive. If the value starts with a dollar sign ($), the dollar sign must be escaped with a backslash (\$)
[ "eq", "$fieldname", "S" ],
(Note the $ prefix).
So your policy should have $ in sets where you using "eq" format
这篇关于通过邮政和ASP.NET MVC的Amazon S3上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!