加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 通过Post和ASP.NET MVC上传Amazon S3

发布时间:2020-12-16 06:30:18 所属栏目:asp.Net 来源:网络整理
导读:我现在已经徒劳地试了2天才能上传到我的Amazon S3 Bucket.以下是我呈现的表格: form action="http://s3.amazonaws.com/MYBUCKETNAME" method="post" enctype="multipart/form-data" input type="hidden" name="AWSAccessKeyId" value="MYACCESSKEY" / input
我现在已经徒劳地试了2天才能上传到我的Amazon S3 Bucket.以下是我呈现的表格:

<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>

我的政策文件如下:

{
        expiration = "2011-12-08T12:00:00.000Z",conditions = [
                ["eq","bucket","MYBUCKETNAME"],["eq","acl","private"],["starts-with","$key","UserUploads/TestUser/"],"success_action_redirect","HTTP://WWW.MYURL.COM/"]
            ]
    }

我收到以下错误:
代码:AccessDenied,
消息:根据策略无效:策略条件失败:[“eq”,“bucket”,“MYBUCKETNAME”]

有没有人有任何想法,我在这里抓住稻草.还不确定我的Bucket Policy和ACL是否正确.

解决方法

根据 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" ],

(注意$前缀).

所以你的政策应该有$in set,你使用“eq”格式

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读