Update CORS config to the one that Uppy recommends

We also switch to the raw XML format, as I think it's easy enough to make the update through the AWS S3 Console after all. Closes #1
parent 9fa42251
...@@ -15,32 +15,38 @@ gem "uppy-s3_multipart" ...@@ -15,32 +15,38 @@ gem "uppy-s3_multipart"
## Setup ## Setup
Once you've created your S3 bucket, you need to set up CORS for it. The In order to allow direct multipart uploads to your S3 bucket, we need to update
following script sets up minimal CORS configuration needed for multipart the bucket's CORS configuration. In the AWS S3 Console go to your bucket, click
uploads on your bucket using the `aws-sdk-s3` gem: on "Permissions" tab and then on "CORS configuration". There paste in the
following:
```rb
require "aws-sdk-s3" ```xml
<?xml version="1.0" encoding="UTF-8"?>
client = Aws::S3::Client.new( <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
access_key_id: "<YOUR KEY>", <CORSRule>
secret_access_key: "<YOUR SECRET>", <AllowedOrigin>https://my-app.com</AllowedOrigin>
region: "<REGION>", <AllowedMethod>GET</AllowedMethod>
) <AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
client.put_bucket_cors( <MaxAgeSeconds>3000</MaxAgeSeconds>
bucket: "<YOUR BUCKET>", <AllowedHeader>Authorization</AllowedHeader>
cors_configuration: { <AllowedHeader>x-amz-date</AllowedHeader>
cors_rules: [{ <AllowedHeader>x-amz-content-sha256</AllowedHeader>
allowed_headers: ["Authorization", "Content-Type", "Origin", "ETag"], <AllowedHeader>content-type</AllowedHeader>
allowed_methods: ["GET", "POST", "PUT", "DELETE"], <ExposeHeader>ETag</ExposeHeader>
allowed_origins: ["*"], </CORSRule>
max_age_seconds: 3000, <CORSRule>
}] <AllowedOrigin>*</AllowedOrigin>
} <AllowedMethod>GET</AllowedMethod>
) <MaxAgeSeconds>3000</MaxAgeSeconds>
</CORSRule>
</CORSConfiguration>
``` ```
Replace `https://my-app.com` with the URL to your app (in development you can
set this to `*`). Once you've clicked `Save`, it may take some time for the
new CORS settings to be applied.
## Usage ## Usage
This gem provides a Rack application that you can mount inside your main This gem provides a Rack application that you can mount inside your main
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment