Download Amazon S3 via Post and ASP.NET MVC

I tried in vain for 2 days to make a simple download to my Amazon S3 bucket. Below is my visual 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 political document is as follows:

  { 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 the policy: The status of the policy is not fulfilled: ["eq", "bucket", "MYBUCKETNAME"]

Does anyone have any ideas, I grab hold of a straw here. Also not sure my bucket and ACL policies are correct.

+4
source share
3 answers

According to http://doc.s3.amazonaws.com/proposals/post.html#Access_Control

Matching a specific value

Description. There are certain fields that you want to map a specific value to, for example, matching a bucket name or requiring the object to be loaded using an open access control policy. the field value is case sensitive, but no name is specified.

Syntax: There are two ways to require a match for field fieldname 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 use the "eq" format

+4
source

Why not do it in C # with the S3 SDK (http://aws.amazon.com/sdkfornet/), it's a bit more secure.

Here's my blog post with more details: http://bradoyler.com/post/3614362044/uploading-an-image-with-aws-sdk-for-net-c .

Greetings and good luck.

+2
source

The following error appeared: Invalid according to the policy: the state of the policy is not fulfilled: [\ "eq \", \ "$ bucket \"

After many hours, I found out that you cannot have a bucket with capital letters. Changing the bucket to lower case fixed it.

+1
source

Source: https://habr.com/ru/post/1385110/


All Articles