Skip to content

Instantly share code, notes, and snippets.

@ngtrieuvi92
Forked from simonw/configuring_cors_s3.md
Created June 29, 2021 08:03
Show Gist options
  • Save ngtrieuvi92/b47d14ded65b12f2fac943484622868d to your computer and use it in GitHub Desktop.
Save ngtrieuvi92/b47d14ded65b12f2fac943484622868d to your computer and use it in GitHub Desktop.
Configuring CORS on Amazon S3 for direct image upload from JavaScript

Configuring CORS on Amazon S3 for direct image upload from JavaScript

I needed to add CORS headers so that client-side JavaScript could upload images directly to an S3 bucket.

I used the Amazon S3 console tool https://console.aws.amazon.com/s3/home?region=us-east-1#&bucket=name-of-bucket&prefix=

Permissions -> Add CORS Configuration

And added the following:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>DELETE</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment