Skip to content
Media CloudDocs
Happy HolidaysSave 20% with codeValid through December 31Shop the sale
Setting Up Cloudflare R2
On this page

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.

4 min read·4 tags

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.dev subdomain.

Step 1 – Create a bucket

  1. Log in to the Cloudflare dashboard.
  2. Open R2 Object Storage.
  3. Click Create bucket.
  4. Enter a name and choose a location.
  5. Click Create bucket.

Step 2 – Enable public access

Media Cloud serves every file from a public URL, so the bucket must be publicly readable.

  1. Open the bucket and go to Settings.
  2. Under Public access, connect a Custom Domain, or enable the r2.dev subdomain for testing.
  3. 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

  1. In R2 Object Storage, open Manage R2 API Tokens.
  2. Click Create API token.
  3. Give the token a name.
  4. Set the permission to Object Read & Write.
  5. Scope the token to the bucket you created.
  6. Click Create API token.
  7. 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.

  1. Open the bucket and go to Settings → CORS policy.
  2. Add a policy:
[
  {
    "AllowedOrigins": ["https://example.com"],
    "AllowedMethods": ["GET", "HEAD", "PUT"],
    "AllowedHeaders": ["*"],
    "ExposeHeaders": ["ETag"],
    "MaxAgeSeconds": 3600
  }
]
  1. Replace https://example.com with your site’s origin. Add separate entries for https://www.example.com and any other domains that serve the site.
  2. Save the policy.

If you skip CORS, normal uploads through WordPress still work, but browser direct uploads fail.

Step 6 – Configure Media Cloud

  1. In WordPress, go to Media Cloud → Settings → Cloud Storage.
  2. Set Storage Provider to Cloudflare R2 Storage.
  3. Fill in the provider settings:
FieldValue
Access KeyR2 Access Key ID
SecretR2 Secret Access Key
BucketBucket name
Custom Endpointhttps://<ACCOUNT_ID>.r2.cloudflarestorage.com
Public Bucket URLThe custom domain or r2.dev URL from step 2
  1. Turn on Enable Cloud Storage.
  2. Save the settings.
  3. 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-Control and Expires metadata 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

ProblemLikely cause
Test upload returns 403The API token is missing Object Read & Write, or it is scoped to a different bucket.
Files upload but the public URL returns 404Public access is not enabled, or the Public Bucket URL does not match the bucket’s public hostname.
Direct uploads fail with a CORS errorThe 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 endThe Public Bucket URL is wrong, or the CDN in front of it is not purging.
The storage tool will not enableAccess 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.

Contact support
Start typing to search the docs

Escto close·⌘Kto open

View all results →