Skip to content
Browse files

Document CORS configuration for direct uploads

Closes #32581.
Closes #34028.
Closes #37343.
  • Loading branch information...
georgeclaghorn committed Oct 9, 2019
1 parent cb495ab commit a3d54d2afe557b243d6b18f9adf119f60ffb8242
Showing with 68 additions and 2 deletions.
  1. +68 −2 guides/source/
@@ -510,7 +510,7 @@ Direct Uploads
Active Storage, with its included JavaScript library, supports uploading
directly from the client to the cloud.

### Direct upload installation
### Usage

1. Include `activestorage.js` in your application's JavaScript bundle.

@@ -532,7 +532,73 @@ directly from the client to the cloud.
<%= form.file_field :attachments, multiple: true, direct_upload: true %>
3. That's it! Uploads begin upon form submission.

3. Configure CORS on third-party storage services to allow direct upload requests.

4. That's it! Uploads begin upon form submission.

### Cross-Origin Resource Sharing (CORS) configuration

To make direct uploads to a third-party service work, you’ll need to configure the service to allow cross-origin requests from your app. Consult the CORS documentation for your service:

* [S3](
* [Google Cloud Storage](
* [Azure Storage](

Take care to allow:

* All origins from which your app is accessed
* The `PUT` request method
* The following headers:
* `Origin`
* `Content-Type`
* `Content-MD5`
* `Content-Disposition` (except for Azure Storage)
* `x-ms-blob-content-disposition` (for Azure Storage only)
* `x-ms-blob-type` (for Azure Storage only)

#### Example: S3 CORS configuration

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="">

#### Example: Google Cloud Storage CORS configuration

"origin": [""],
"method": ["PUT"],
"responseHeader": ["Origin", "Content-Type", "Content-MD5", "Content-Disposition"],
"maxAgeSeconds": 3600

#### Example: Azure Storage CORS configuration

<AllowedHeaders>Origin, Content-Type, Content-MD5, x-ms-blob-content-disposition, x-ms-blob-type</AllowedHeaders>

### Direct upload JavaScript events

1 comment on commit a3d54d2


This comment has been minimized.

Copy link

connorshea commented on a3d54d2 Oct 9, 2019

Thank you!

Please sign in to comment.
You can’t perform that action at this time.