Skip to content

Instantly share code, notes, and snippets.

@simonw
Last active June 29, 2021 08:03
Show Gist options
  • Save simonw/3cbb3a787ce218d9bcf6a4650b0bae36 to your computer and use it in GitHub Desktop.
Save simonw/3cbb3a787ce218d9bcf6a4650b0bae36 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