Connect Cloudflare R2 storage
This article walks you through creating a Cloudflare R2 bucket and connecting it to PlayerMagick, so your videos are stored and played from your own Cloudflare account.
This is optional. PlayerMagick stores your videos for you, with nothing to set up. Connecting your own bucket is only for accounts where it is turned on: accounts that already used their own storage, and accounts where support turned it on at your request. See How PlayerMagick stores your videos.
Cloudflare R2 is the storage we recommend: Cloudflare does not charge when people watch your videos, and when you use your own domain, videos are delivered through Cloudflare's worldwide network.
Before you start
- You need a Cloudflare account with R2 turned on. Cloudflare may ask for a payment method before you can use R2, even on the free allowance.
- To use your own address for videos (recommended), the domain must be managed in the same Cloudflare account, for example
yourdomain.com. - Keep this article and the Cloudflare dashboard open side by side. You will copy four values into PlayerMagick.
Cloudflare sometimes renames buttons in its dashboard. If a label below does not match exactly, look for the closest one.
Step 1: Create a bucket
- Log in to the Cloudflare dashboard and open R2 Object Storage.
- Click Create bucket.
- Enter a bucket name, for example
sales-videos. Use lowercase letters, numbers and hyphens only. - Leave Location on Automatic.
- Click Create bucket.
Step 2: Give your videos a public address
Visitors' browsers need an address to load your videos from. You have two choices.
Your own domain (recommended for live sales pages)
- Open your bucket and go to Settings.
- Under Custom Domains, click Add.
- Enter a subdomain you do not use yet, for example
videos.yourdomain.com, and click Continue. - Confirm with Connect Domain.
- Wait until the domain shows Active. This usually takes a few minutes.
Your public address is https://videos.yourdomain.com.
Then let Cloudflare keep copies of your videos close to your viewers. By default it does not keep the small files a streamed video is made of, so every viewer would load them from your bucket and videos would start slower. One rule fixes it:
- In the Cloudflare dashboard, open your domain (for example
yourdomain.com) and go to Caching → Cache Rules. - Click Create rule and name it, for example
Videos. - Under If incoming requests match, choose Hostname equals and enter your subdomain, for example
videos.yourdomain.com. - Under Cache eligibility, choose Eligible for cache. Leave the other settings as they are.
- Click Deploy.
This is safe: PlayerMagick never changes a converted file (a new version goes in a new folder), and your original uploads are never cached. Without the rule, PlayerMagick shows the reminder "Cloudflare doesn’t keep copies of your videos yet" when it tests the connection.
The free r2.dev address (for testing only)
- Open your bucket and go to Settings.
- Under Public Development URL, click Enable, type
allowand confirm. - Copy the address shown. It looks like
https://pub-1a2b3c….r2.dev.
Cloudflare limits how many requests an r2.dev address may serve and does not speed it up with its network, so it is not meant for real visitors. PlayerMagick accepts it, but shows a reminder under "Read it back through the public URL" until you switch to your own domain. Switch before you send real traffic to your page.
Step 3: Let the player load your videos (CORS)
Your videos are loaded by the player on your sales page, which is a different website from your storage. Browsers only allow this when the bucket says so. This permission is called CORS. The key you create in step 4 is limited to your files and cannot change this setting, so you add it yourself, once.
- In your bucket, go to Settings.
- Under CORS Policy, click Add CORS policy (or Edit).
- If the box is empty, paste the text below exactly. If the bucket already has rules, keep them and add these two rules to the list (inside the same square brackets, separated by a comma):
[
{
"AllowedOrigins": ["*"],
"AllowedMethods": ["GET", "HEAD"],
"AllowedHeaders": ["Range"],
"ExposeHeaders": ["Content-Length", "Content-Range", "ETag"],
"MaxAgeSeconds": 86400
},
{
"AllowedOrigins": ["https://app.playermagick.com"],
"AllowedMethods": ["PUT"],
"AllowedHeaders": ["*"],
"ExposeHeaders": ["ETag"],
"MaxAgeSeconds": 3600
}
]
- Click Save.
The first rule lets any website play your videos (which websites may show them is controlled separately in PlayerMagick, see Choose which websites can play your video). The second rule lets you upload from PlayerMagick straight into your bucket.
Never delete rules you or someone else added for another website or tool: they keep working next to these two.
Step 4: Create a key for PlayerMagick
- Go back to the R2 Object Storage overview page.
- Click Manage API tokens (you may find it under API or Account details).
- Click Create Account API token (or Create API token).
- Name it
PlayerMagick. - Under Permissions, choose Object Read & Write.
- Under Specify bucket(s), choose Apply to specific buckets only and select your bucket. This way the key can only touch this one bucket.
- Leave TTL on Forever (if the key expires, your uploads and conversions stop).
- Click Create API Token.
- Copy the Access Key ID and the Secret Access Key and keep them somewhere safe for the next step. Cloudflare shows the secret only once.
You do not need the Token value shown on the same page.
Step 5: Find your Account ID
On the R2 Object Storage overview page, look for Account ID (under Account details). It is 32 characters long, letters a–f and numbers, for example 0123456789abcdef0123456789abcdef.
Step 6: Connect the bucket in PlayerMagick
- In PlayerMagick, open the Storage step of the first setup, or go to Settings → Storage and click Connect a bucket.
- Choose Cloudflare R2.
- Fill in:
- Account ID: from step 5.
- Bucket name: from step 1, for example
sales-videos. - Access key ID and Secret access key: from step 4.
- Public URL for playback: from step 2, for example
https://videos.yourdomain.com.
- Click Test connection. PlayerMagick checks the connection and ticks each line as soon as it passes, usually within a few seconds and never longer than about 45 seconds:
- "Wrote a test file"
- "Read it back through the public URL"
- "Deleted it"
- "Set up browser uploads (CORS) for you"
- When all four are ticked, the button changes to Save and continue. Click it. A reminder under a ticked line (for example about the r2.dev address) does not stop you from saving.
Chose the wrong provider? Click Change provider. Want to do this later? In the first setup, click Skip for now; you can connect from Settings → Storage at any time, but you need a bucket before you can upload.
Troubleshooting
- The last check fails ("Set up browser uploads (CORS) for you"): do step 3 again, check that you pasted the whole text and clicked Save, then click Test again.
- "Read it back through the public URL" fails: check that the custom domain shows Active or that the r2.dev address is enabled, and that you copied it without extra characters. Use only the address, with nothing after the domain.
- A reminder says the r2.dev address is for testing only: connect your own domain (step 2), then change the public URL. See Fix a storage connection test error.
- The first check fails: the keys or the Account ID are wrong, or the key is not allowed to use this bucket. Create a new key (step 4) and click Test again.
Every message is explained in Fix a storage connection test error.