我使用基于浏览器的直接 POST 上传和 Amazon S3 有一段时间了,最近我想开始通过 HTTPS 发布。正常的 HTTP 帖子工作得很好。但是,当我将相同的表格发布到 https://s3.amazonaws.com/ 时,我收到“不允许使用 405 方法”。
基于浏览器的直接 AWS POST 上传是否不支持 HTTPS?如果他们这样做,我怎样才能在不收到 405 错误的情况下做到这一点?
谢谢!
最佳答案
这可能是您的 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
关于此还有另一篇文章。 Amazon S3 - HTTPS/SSL - Is it possible?
更新: 我能够使用此 HTML 和策略通过 SSL 将对象上传到 S3 存储桶。检查表单操作。
政策:
{
"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>
您必须知道如何生成编码策略和签名。
关于post - 如何通过 SSL 将文件直接上传到 S3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9894994/