【问题标题】:S3 buckets CORS policy DjangoS3 存储桶 CORS 策略 Django
【发布时间】:2021-03-31 22:07:14
【问题描述】:

我正在尝试设置一个 s3 存储桶,以便我的 Django 应用可以上传和抓取用户媒体文件。 我来到了这个视频https://www.youtube.com/watch?v=kt3ZtW9MXhw&t=224s 中你设置 cors 政策的部分。

在本教程中,他使用 XML,但 aws 现在需要 json。我不知道该放什么。我希望我的网站能够进行 GET、PUT、POST、PATCH 和 DELETE。

我的应用是托管在 Digital Ocean 液滴上的 Django 应用

编辑:我找到了一个我已经编辑并添加到我的配置中的示例

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "PUT",
            "POST",
            "DELETE"
        ],
        "AllowedOrigins": [
            "http://www.example1.com"
        ],
        "ExposeHeaders": []
    },
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "PUT",
            "POST",
            "DELETE"
        ],
        "AllowedOrigins": [
            "http://www.example2.com"
        ],
        "ExposeHeaders": []
    },
    {
        "AllowedHeaders": [],
        "AllowedMethods": [
            "GET"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": []
    }
]

【问题讨论】:

    标签: amazon-web-services amazon-s3 django-cors-headers


    【解决方案1】:

    用于配置cors:-

    1. 你需要给public access to bucket.(通过桶策略和 控制台)https://stackoverflow.com/a/4709391/13126651(用于公共访问存储桶策略)
    2. 确保将您的存储桶用作网站,然后在您的存储桶 cors 设置下附加此策略。
    [
        {
            "AllowedHeaders": [
                "Authorization"
            ],
            "AllowedMethods": [
                "GET"
            ],
            "AllowedOrigins": [
                "<url of first bucket with http://...without slash at the end>"
            ],
            "ExposeHeaders": [],
            "MaxAgeSeconds": 3000
        }
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-26
      • 2021-01-19
      • 2015-03-14
      • 2013-01-08
      相关资源
      最近更新 更多