amazon-s3 - S3 在 https 上上传,存储桶名称中带有点

标签 amazon-s3 https

我一直在尝试在使用https的网站上实现ajax上传到Amazon的S3,所以当然我也必须上传到S3的安全版本,https://bucket.name.s3.amazonaws.com 。但是,当我尝试此上传时,最终收到错误消息,指出该网站的安全证书无效。根据我的阅读,这是预期的,因为亚马逊的 s3 证书仅涵盖一级子域( http://shlomoswidler.com/2009/08/amazon-s3-gotcha-using-virtual-host.html )。因此,我将要上传的 URL 更改为 https://s3.amazonaws.com/bucket.name ,从我也读过的内容来看,应该相当于 https://bucket.name.s3.amazonaws.com 。然而,尝试上传时出现了 301 永久重定向错误。我知道我的代码确实有效,因为当我尝试上传到名称中没有点的存储桶时,到 https://bucket.s3.amazonaws.com ,一切顺利,但当我尝试 https://s3.amazonaws.com/bucket 时,它也得到 301 。

 <form id="form">
    <input type="hidden" name="key" value="..." />
    <input type="hidden" name="acl" value="public-read" />
    <input type="hidden" name="X-Amz-Credential" value="..." />
    <input type="hidden" name="X-Amz-Algorithm" value="..." />
    <input type="hidden" name="X-Amz-Date" value="..." />
    <input type="hidden" name="Policy" value="..." />
    <input type="hidden" name="X-Amz-Signature" value="..." />
    <input type="hidden" name="success_action_redirect" value="..." />
    <input id="upload" type="submit" value="Upload" class="submit-upload clearfix button blue save"/>
</form>

<script type="text/javascript">
     document.getElementById('upload').addEventListener('click', function (e) {
          e.preventDefault();
          var formData = new FormData(document.getElementById('form'));
          var xhr = new XMLHttpRequest();
          xhr.open('POST', 'https://s3.amazonaws.com/bucket.name/', true);
          xhr.send(formData);
     });
</script>

所以我的问题是:有没有办法通过 https 实现 ajax 上传到名称中带有点的 S3 存储桶?

最佳答案

关于http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html

Amazon S3 supports virtual hosted-style and path-style access in all regions. The path-style syntax, however, requires that you use the region-specific endpoint when attempting to access a bucket. For example, if you have a bucket called mybucket that resides in the EU, you want to use path-style syntax, and the object is named puppy.jpg, the correct URI is http://s3-eu-west-1.amazonaws.com/mybucket/puppy.jpg. You will receive a "PermanentRedirect" error, an HTTP response code 301, and a message indicating what the correct URI is for your resource if you try to access a bucket outside the US East (N. Virginia) region with path-style syntax that uses either of the following:

关于amazon-s3 - S3 在 https 上上传,存储桶名称中带有点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35705616/

相关文章:

rest - Docker 容器中的 HTTP 请求因 HTTPS 端点而失败

node.js - 启用 SSL 时禁用 HTTP

java - 从 X509Certificate 获取 HttpsURLConnection 的 SSL 上下文

java - Maven部署打包并上传到AWS-Lambda

python - Django 静态文件相对引用 Amazon S3

android - HTTPS 证书有时会在 Android WebView 中失败

php - PHP SoapClient 是否支持 HTTPS 连接

ruby-on-rails - S3 的 Assets 路径问题

java - 使用 java 将文件上传到 Amazon S3 失败 - sun.security.validator.ValidatorException

amazon-web-services - Terraform:如何在项目之间迁移状态?