如何通过 SSL 将文件直接上传到 S3?

2024-05-05

我已经使用基于浏览器的 Amazon S3 直接 POST 上传有一段时间了,最​​近想开始通过 HTTPS 发布。普通的 HTTP 帖子就可以正常工作。但是,当我将相同的表格发布到https://s3.amazonaws.com/ https://s3.amazonaws.com/,我收到“405 方法不允许”。

基于浏览器的直接 AWS POST 上传不支持 HTTPS 吗?如果他们这样做了,我怎样才能做到这一点而不出现 405 错误?

Thanks!


这可能是您的 HTML FORM 操作出现问题。

The action specifies the URL that processes the request, which must be set to the URL of the
bucket. For example, if the name of your bucket is "johnsmith", the URL 
is "http://johnsmith.s3.amazonaws.com/".

请查看此 AMAZON S3 文档链接以了解更多详细信息:http://docs.amazonwebservices.com/AmazonS3/latest/dev/HTTPPOSTForms.html#HTTPPOSTFormDeclaration http://docs.amazonwebservices.com/AmazonS3/latest/dev/HTTPPOSTForms.html#HTTPPOSTFormDeclaration

还有另一篇文章对此进行了阐述。Amazon S3 - HTTPS/SSL - 可能吗? https://stackoverflow.com/questions/3048236/amazon-s3-https-ssl-is-it-possible

UPDATE:我能够使用此 HTML 和策略通过 SSL 将对象上传到 S3 存储桶。检查表单操作。

Policy :

{
  "expiration": "2012-06-04T12:00:00.000Z",
  "conditions": [
    {"bucket": "<YourBucketName>" },
    {"acl": "public-read" },
    ["eq", "$key", "testImage.jpg"],
    ["starts-with", "$Content-Type", "image/jpeg"],
  ]
}

HTML:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="https://s3.amazonaws.com/<YourBucketName>/" method="post" enctype="multipart/form-data">
<input type="text" name="key" value="testImage.jpg" />
<input type="text" name="acl" value="public-read" />
<input type="text" name="content-type" value="image/jpeg" />
<input type="hidden" name="AWSAccessKeyId" value="<YOUR ACCESS KEY>" />
<input type="hidden" name="policy" value="<YOUR GENERATED POLICY>" />
<input type="hidden" name="signature" value="<YOUR GENERATED SIGNATURE>" />
<input name="file" type="file" />
<input name="submit" value="Upload" type="submit" />
</form>
</body>
</html>

您必须知道如何生成编码策略和签名。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何通过 SSL 将文件直接上传到 S3? 的相关文章

随机推荐