基于Amazon S3浏览器的上传和405方法不允许错误

时间:2017-08-02 09:44:29

标签: amazon-s3 upload

我正在尝试为任何人(即公共)创建一种将文件上传到Amazon S3存储桶的方法,因此阅读了大量文档但由于我在这个领域的技术不成熟而遇到障碍。这是我做的:

(1)创建一个S3存储桶并将其设置为托管静态网站

(2)将此存储桶策略直接添加到此存储桶:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadForGetBucketObjects",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Resource": "arn:aws:s3:::testjn/*"
        }
    ]
}

(3)创建一个index.html,其HTML内容从此处填充并加载到存储桶(称为testjn):

http://s3.amazonaws.com/doc/s3-example-code/post/post_sample.html

index.html看起来像这样:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="[this is the endpoint]" method="post" enctype="multipart/form-data">
<input type="text" name="key" value="testfile.txt" />
<input type="text" name="acl" value="public-read" />
<input type="text" name="content-type" value="text/plain" />
<input type="hidden" name="AWSAccessKeyId" value="[this is the access key]" />
<input type="hidden" name="policy" value="ewogICJleHBpcmF0aW9uIjogIjIwMDktMDEtMDFUMTI6MDA6MDAuMDAwWiIsCiAgImNvbmRpdGlvbnMiOiBbCiAgICB7ImJ1Y2tldCI6ICJ0ZXN0am4iIH0sCiAgICB7ImFjbCI6ICJwdWJsaWMtcmVhZCIgfSwKICAgIFsiZXEiLCAiJGtleSIsICJ0ZXN0ZmlsZS50eHQiXSwKICAgIFsic3RhcnRzLXdpdGgiLCAiJENvbnRlbnQtVHlwZSIsICJ0ZXh0LyJdLAogIF0KfQo=" />
<input type="hidden" name="signature" value="mQEx+XUAJAVcuG+uip0EtmFs6Xo=" />
<input name="file" type="file" />
<input name="submit" value="Upload" type="submit" />
</form>
</body>
</html>

(4)使用此策略创建IAM角色:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowGroupToSeeBucketListAndAlsoAllowGetBucketLocationRequiredForListBucket2",
            "Action": [
                "s3:ListAllMyBuckets",
                "s3:GetBucketLocation"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::*"
            ]
        },
        {
            "Sid": "AllowRootLevelListingOfCompanyBucket2",
            "Action": [
                "s3:PutObject",
                "s3:ListBucket",
                "s3:GetBucketLocation"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::testjn",
                "arn:aws:s3:::testjn/*"
            ]
        }
    ]
}

(5)我在尝试上传时不断收到“405 Method Not Allowed”错误,所以认为这与2条政策或其他内容有关......我已经阅读并研究了4周并拉我所有的头发。所以请有人建议。感谢

0 个答案:

没有答案