Skip to content

Instantly share code, notes, and snippets.

@gregorynicholas
Forked from simonw/configuring_cors_s3.md
Created June 19, 2018 18:41
Show Gist options
  • Save gregorynicholas/fc001c4567e9200eaafbfc41bc125a6e to your computer and use it in GitHub Desktop.
Save gregorynicholas/fc001c4567e9200eaafbfc41bc125a6e 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