Documentation
StorageProviders

Cloudflare R2 Storage

Configure and use Cloudflare R2 to host your file uploads with zero egress fees.

Follow these steps to configure a Cloudflare R2 bucket and acquire the necessary environment variables to enable S3-compatible file uploads.

Create an R2 Bucket

  1. Log in to your Cloudflare Dashboard.
  2. In the left sidebar, navigate to R2.
  3. Click Create bucket.
  4. Enter a name for your bucket (e.g., golivekit-storage) and click Create bucket.
  5. (Optional) To make publicly accessible files, navigate to the Settings tab of your bucket and enable Public URL under the Public Access section.

Configure CORS

Because files are uploaded directly from the browser using presigned URLs, you need to configure CORS (Cross-Origin Resource Sharing).

  1. Inside your bucket settings, scroll down to CORS policy.
  2. Click Add CORS policy.
  3. Paste the following JSON configuration (you can restrict AllowedOrigins in production):
[
  {
    "AllowedOrigins": [
      "*"
    ],
    "AllowedMethods": [
      "GET",
      "PUT",
      "POST",
      "HEAD"
    ],
    "AllowedHeaders": [
      "*"
    ]
  }
]
  1. Save the policy.

Generate API Tokens

  1. Go back to the main R2 dashboard overview.
  2. On the right side of the screen, click Manage R2 API Tokens.
  3. Click Create API token.
  4. Give your token a descriptive name (e.g., GoLiveKit File Uploads).
  5. Under Permissions, select Object Read & Write.
  6. Under Specify bucket(s), select the specific bucket you created earlier or allow all.
  7. Click Create API Token.

Copy Your Credentials

After creating the token, Cloudflare will display your credentials. Copy them immediately, as the Secret Access Key will never be shown again.

You will need:

  • Access Key ID
  • Secret Access Key
  • Jurisdiction-specific endpoint (The URL that looks like https://<ACCOUNT_ID>.r2.cloudflarestorage.com)

Update your .env

Fill in your .env file with the keys and endpoint you copied. R2 uses "auto" for the region.

.env
S3_REGION=auto
S3_BUCKET=your-bucket-name
S3_ACCESS_KEY_ID=your-copied-access-key-id
S3_SECRET_ACCESS_KEY=your-copied-secret-access-key
S3_ENDPOINT=https://your-account-id.r2.cloudflarestorage.com # IMPORTANT: Required for R2

On this page