Skip to content

Instantly share code, notes, and snippets.

@awesome
Forked from basti/README.md
Created January 13, 2023 22:36
Show Gist options
  • Save awesome/f4c4b0b7e436c1624684551dca0d7f70 to your computer and use it in GitHub Desktop.
Save awesome/f4c4b0b7e436c1624684551dca0d7f70 to your computer and use it in GitHub Desktop.
AWS S3 CORS configuration for Rails ActiveStorage

AWS S3 now uses JSON for CORS configuration and cors.json is minimal configuration for Rails 7 direct uploads.

[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"PUT"
],
"AllowedOrigins": [
"https://www.example.com"
],
"ExposeHeaders": [
"Origin",
"Content-Type",
"Content-MD5",
"Content-Disposition"
],
"MaxAgeSeconds": 3600
}
]
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>https://staging.example.com</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>https://staging.example.com</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Content-Type</AllowedHeader>
<AllowedHeader>Content-MD5</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment