How do you upload files directly to S3 over SSL?

让人想犯罪 __ 提交于 2021-02-07 03:32:42

问题


I've been using browser based direct POST uploads with Amazon S3 for a while, and just recently wanted to start posting through HTTPS. Normal HTTP posts work just fine. However, when I post the same form to https://s3.amazonaws.com/, I get a "405 Method Not Allowed".

Do browser based direct AWS POST uploads not support HTTPS? If they do, how can I do it without getting a 405 error?

Thanks!


回答1:


It could be some problem with your HTML FORM action.

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/".

Please check this AMAZON S3 documentation link for more detail: http://docs.amazonwebservices.com/AmazonS3/latest/dev/HTTPPOSTForms.html#HTTPPOSTFormDeclaration

There is also a another post on this. Amazon S3 - HTTPS/SSL - Is it possible?

UPDATE: I was able to upload objects to S3 bucket over SSL using this HTML & Policy.Check the form action.

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>

You must know how to generate encoded policy and signature.



来源:https://stackoverflow.com/questions/9894994/how-do-you-upload-files-directly-to-s3-over-ssl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!