Skip to content

Instantly share code, notes, and snippets.

@jsoma
Last active May 11, 2023 09:21
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jsoma/5830e8b7dc083f12298d4f5f8c72d650 to your computer and use it in GitHub Desktop.
Save jsoma/5830e8b7dc083f12298d4f5f8c72d650 to your computer and use it in GitHub Desktop.
CORS public access (new JSON version)
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"PublicRead",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject","s3:GetObjectVersion"],
"Resource":["arn:aws:s3:::YOUR_BUCKET_NAME_GOES_HERE/*"]
}
]
}
@na5imuzzaman
Copy link

na5imuzzaman commented Feb 24, 2021

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
           "GET",
            "PUT",
            "POST",
            "DELETE"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": [
            "x-amz-server-side-encryption",
            "x-amz-request-id",
            "x-amz-id-2"
        ],
        "MaxAgeSeconds": 3000
    }
]

@otherperspectives
Copy link

Thank you!

@itsafo
Copy link

itsafo commented May 8, 2021

It works

@gmarshall56
Copy link

Still have the problem:
Access to XMLHttpRequest at '<< myS3Bucket.png' from origin 'http://localhost:3000' (React App running locally) has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

@steven-tey
Copy link

steven-tey commented Jun 18, 2021

@gmarshall56 same, but I made it work by adding crossorigin="anonymous" to all my <img> tags! Hope that works for you too!!

@rn2web
Copy link

rn2web commented Jul 27, 2021

do not work.

@GiriAakula
Copy link

GiriAakula commented Dec 29, 2021

Add this in Bucket > Permissions > Scroll down to bottom to Cross-origin resource sharing (CORS) and add this

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET",
            "HEAD"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": [],
        "MaxAgeSeconds": 3000
    }
]

@dfloresgonz
Copy link

does this work for fetching jpgs?

@GiriAakula
Copy link

Yes

@dfloresgonz
Copy link

does this configuration change affect old files? or I have to re-upload my old content?

@na5imuzzaman
Copy link

Effective for whole bucket.

@dfloresgonz
Copy link

Even old existing files? Weird my code works with files added after I changed the configuration but not with the ones that existed previous my change of configuration

@dfloresgonz
Copy link

it is only working in some browsers, is there a solution for this?

@itsjyde
Copy link

itsjyde commented May 25, 2022

This worked for me. Thanks

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
           "GET",
            "PUT",
            "POST",
            "DELETE"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": [
            "x-amz-server-side-encryption",
            "x-amz-request-id",
            "x-amz-id-2"
        ],
        "MaxAgeSeconds": 3000
    }
]

@Sebastian2908-2007
Copy link

[
{
"AllowedHeaders": [
""
],
"AllowedMethods": [
"GET",
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"
"
],
"ExposeHeaders": [
"x-amz-server-side-encryption",
"x-amz-request-id",
"x-amz-id-2"
],
"MaxAgeSeconds": 3000
}
]
July 2022 this works!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment