【问题标题】:Can't add http://localhost to DigitalOcean Spaces CORS Rules无法将 http://localhost 添加到 DigitalOcean Spaces CORS 规则
【发布时间】:2021-04-07 22:31:57
【问题描述】:

从图片中可以看出,目前无法将 http://localhost 添加为 CORS 规则。

【问题讨论】:

  • 只是出于好奇,这是 AWS S3 的问题,还是我们正在谈论数字海洋,因为在我看来,在随附的屏幕截图以及问题标题中的数字海洋中。但标签是亚马逊网络服务。
  • 问题在于 DigitalOcean。我将编辑标签@samtoddler
  • 在这种情况下,以下答案与 AWS S3 服务相关,因此可能无济于事。
  • 它会的,DigitalOcean API 与大多数 Amazon S3 开发工具包和功能兼容。例如,您可以在 Node 中包含 Amazon 的 aws-sdk npm 包,当使用 DigitalOcean 时,它可以作为即插即用的替代品,就像 i.imgur.com/7ADSW42.png 您可以在此处阅读有关它们如何互操作的更多信息:digitalocean.com/docs/spaces/resources/s3-sdk-examples
  • 我遇到了类似的问题,但以不同的方式解决了它(更新/etc/hosts)。 stackoverflow.com/a/70315253/331655

标签: cors digital-ocean digital-ocean-spaces


【解决方案1】:

要解决此问题,您必须使用s3cmd 等工具。使用此工具的最简单方法是下载源代码。如果您已经安装了 Python,您可以使用以下命令来更改 DigitalOcean Spaces CORS 配置(需要 python 2.7 或更高版本):

注意:您可能还需要安装Gpg4win

首先下载源from here 并解压到任意目录。然后在该目录中运行以下commands。您还应该将 cors.xml 配置放在此目录中。

python s3cmd --configure

这是托管在阿姆斯特丹 3 上的配置的示例输入......

Access Key [YOUR_ACCESS_KEY]:
Secret Key [YOUR_SECRET_KEY]: 
S3 Endpoint [ams3.digitaloceanspaces.com]
DNS-style bucket+hostname:port template for accessing a bucket [%(bucket)s.ams3.digitaloceanspaces.com]:
Encryption password [password]:

python s3cmd ls - 查看您的所有空间

python s3cmd setcors cors.xml s3://your-space-name-here 其中cors.xml 是您工作目录中的一个文件,其中包含标准 cors 配置,例如:

<CORSConfiguration>
 <CORSRule>
   <AllowedOrigin>http://localhost:4000</AllowedOrigin>
   <AllowedMethod>GET</AllowedMethod>
   <AllowedMethod>HEAD</AllowedMethod>
 </CORSRule>
</CORSConfiguration>

运行此最终命令后,您现在应该在 DigitalOcean 仪表板中看到您的原始 CORS 配置现已替换为您保存到 cors.xml 的任何配置

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 2019-08-31
    • 2015-12-13
    • 1970-01-01
    相关资源
    最近更新 更多