1

I'm trying to set up an s3 bucket so my Django app can upload and grab user media files. I've come to the part in this video https://www.youtube.com/watch?v=kt3ZtW9MXhw&t=224s where you set the cors policy.

In this tutorial he uses XML but aws now wants json. I don't know what to put. I want my website to be able to GET, PUT, POST, PATCH and DELETE.

My app is a Django app hosted on a Digital Ocean droplet

Edit: I've found an example which I've edited and added to my config

[
    {
        "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": []
    }
]
Jatin Mehrotra
  • 9,286
  • 4
  • 28
  • 67
nandesuka
  • 699
  • 8
  • 22

1 Answers1

1

For configuring cors:-

  1. you need to give public access to bucket.( through bucket policy and console) https://stackoverflow.com/a/4709391/13126651 ( for public access bucket policy)
  2. make sure to enable your bucket to be used as website and then attach this policy, under your bucket cors setting.
[
    {
        "AllowedHeaders": [
            "Authorization"
        ],
        "AllowedMethods": [
            "GET"
        ],
        "AllowedOrigins": [
            "<url of first bucket with http://...without slash at the end>"
        ],
        "ExposeHeaders": [],
        "MaxAgeSeconds": 3000
    }
]
Jatin Mehrotra
  • 9,286
  • 4
  • 28
  • 67