2012-03-27 118 views
4

我一直在使用基于浏览器的直接POST上传与亚马逊S3一段时间,最近才想开始通过HTTPS发布。普通的HTTP帖子工作得很好。但是,当我将相同的表单发布到https://s3.amazonaws.com/时,我收到“405不允许的方法”。如何通过SSL将文件直接上传到S3?

待办事项基于浏览器的直接AWS POST上传不支持HTTPS?如果他们这样做,我怎么能没有得到405错误呢?

谢谢!

回答

7

这可能是有些问题,你的HTML表单操作。

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?

UPDATE: 我可以上传使用此HTML & Policy.Check表单动作通过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> 

你必须知道如何生成编码的政策和签名。

+0

如果指定一个自定义的斗HTTPS URL,它会抛出一个SSL错误,所以这不是一个选项,很遗憾。 – 2012-03-28 18:57:33

+1

我使用自定义存储桶获得了HTTPS网址。像https://s3.amazonaws.com//。检查我的答案更新。 – shashankaholic 2012-03-28 21:11:53

+0

谢谢!我将不得不检查我正在使用的库的来源,以了解它是如何生成签名的。 – 2012-03-28 21:57:35