Setting Up Cloudflare R2
Connect Media Cloud to a Cloudflare R2 bucket using its S3-compatible API, a public bucket URL and a CORS policy for direct uploads.
Cloudflare R2 is an S3-compatible object storage service. Media Cloud connects to R2 through the S3 API and serves files from the bucket’s public URL or a custom domain.
R2 does not support object ACLs. Every file in a public R2 bucket is publicly readable, and Media Cloud cannot generate pre-signed URLs for R2. The pre-signed URL settings are hidden when R2 is selected. If you need private files or signed downloads for WooCommerce or Easy Digital Downloads, use a provider that supports ACLs, such as Amazon S3 or DigitalOcean Spaces.
Before you start
You need:
- A Cloudflare account with R2 enabled.
- A bucket.
- An R2 API token with Object Read & Write permission.
- Public access enabled through a custom domain or an
r2.devsubdomain.
Step 1 – Create a bucket
- Log in to the Cloudflare dashboard.
- Open R2 Object Storage.
- Click Create bucket.
- Enter a name and choose a location.
- Click Create bucket.
Step 2 – Enable public access
Media Cloud serves every file from a public URL, so the bucket must be publicly readable.
- Open the bucket and go to Settings.
- Under Public access, connect a Custom Domain, or enable the r2.dev subdomain for testing.
- Copy the public URL.
Use the custom domain in production. The r2.dev URL is rate-limited and intended for development.
The Public Bucket URL in Media Cloud must be the URL that serves the bucket root, for example https://media.example.com or https://pub-xxxxxxxx.r2.dev. Do not include the bucket name in the URL.
Step 3 – Create an R2 API token
- In R2 Object Storage, open Manage R2 API Tokens.
- Click Create API token.
- Give the token a name.
- Set the permission to Object Read & Write.
- Scope the token to the bucket you created.
- Click Create API token.
- Copy the Access Key ID and Secret Access Key. The secret is only shown once.
Step 4 – Note the S3 endpoint
The bucket’s S3 endpoint is:
https://<ACCOUNT_ID>.r2.cloudflarestorage.com
You can find the account ID in the Cloudflare dashboard URL or on the R2 overview page.
Step 5 – Configure CORS for direct uploads
Direct uploads send files from the browser straight to R2 with a pre-signed PUT request. R2 must allow requests from your site.
- Open the bucket and go to Settings → CORS policy.
- Add a policy:
[
{
"AllowedOrigins": ["https://example.com"],
"AllowedMethods": ["GET", "HEAD", "PUT"],
"AllowedHeaders": ["*"],
"ExposeHeaders": ["ETag"],
"MaxAgeSeconds": 3600
}
]
- Replace
https://example.comwith your site’s origin. Add separate entries forhttps://www.example.comand any other domains that serve the site. - Save the policy.
If you skip CORS, normal uploads through WordPress still work, but browser direct uploads fail.
Step 6 – Configure Media Cloud
- In WordPress, go to Media Cloud → Settings → Cloud Storage.
- Set Storage Provider to Cloudflare R2 Storage.
- Fill in the provider settings:
| Field | Value |
|---|---|
| Access Key | R2 Access Key ID |
| Secret | R2 Secret Access Key |
| Bucket | Bucket name |
| Custom Endpoint | https://<ACCOUNT_ID>.r2.cloudflarestorage.com |
| Public Bucket URL | The custom domain or r2.dev URL from step 2 |
- Turn on Enable Cloud Storage.
- Save the settings.
- Run the system test from Media Cloud → System Compatibility to upload, read, and delete a sample file.
Optional settings
- Cache Control and Content Expiration in Upload Handling set the
Cache-ControlandExpiresmetadata on uploads. - Upload Path supports the usual path tokens. See Upload Handling Settings.
- A CDN can sit in front of the public bucket URL. Set the CDN URL in CDN Settings.
Direct uploads
Cloudflare R2 supports direct uploads. Enable Direct Uploads under Media Cloud → Settings → Direct Uploads and configure the CORS policy above. Media Cloud 4.7.3 fixed direct uploads on R2; update if uploads fail with a CORS or signature error.
Troubleshooting
| Problem | Likely cause |
|---|---|
| Test upload returns 403 | The API token is missing Object Read & Write, or it is scoped to a different bucket. |
| Files upload but the public URL returns 404 | Public access is not enabled, or the Public Bucket URL does not match the bucket’s public hostname. |
| Direct uploads fail with a CORS error | The bucket’s CORS policy does not allow your site origin, PUT, or the headers the browser sends. |
| Images work in the media library but not on the front end | The Public Bucket URL is wrong, or the CDN in front of it is not purging. |
| The storage tool will not enable | Access Key, Secret, Bucket, Custom Endpoint, or Public Bucket URL is empty. |
Need a hand with this guide?
Send support the exact step you’re stuck on and we’ll help you finish the setup.