On this page

Saving to Cloudflare R2

Introduction

This tutorial is designed to assist you in saving files to Cloudflare R2, a highly compatible and scalable cloud storage solution, using its S3-compatibility mode.

By completing this tutorial, you'll be able to set up a destination object for saving files to Cloudflare R2, understanding the specific URL structure and credentials required.

Supported Protocols

ProtocolDescription
s3://Cloudflare R2 Storage in S3-Compatible Mode

1
Creating a Bucket in Cloudflare R2

  1. Sign in to your Cloudflare account and navigate to the R2 storage service.
  2. Create a new storage bucket, choosing a unique name for it.

2
Finding Your Cloudflare R2 Credentials

  1. In Account Home, select R2.
  2. Select Manage R2 API tokens and than select Create API token.
  3. Select the R2 Token text to edit your API token name.
  4. Under Permissions, choose a permission types for your token.
  5. Select Create API Token.

After your token has been successfully created, review your Secret Access Key and Access Key ID values.

Remember, you need to have purchased R2 to generate an API token.

For more information and process of getting credentials, refer to the official Cloudflare documentation.

3
Saving Output to Cloudflare R2

In order to save your outputs to your Cloudflare R2 Storage, define your destination object using the following structure.

Destination Object Structure

"destination": {
  "url": "s3://[account_id].r2.cloudflarestorage.com/bucket/path",
  "key": "access_key_id",
  "secret": "secret_access_key"
}

Attributes of Cloudflare Destination Object

AttributeDescription
urlYour Cloudflare URL.
keyYour Cloudflare R2 access key ID.
secretYour Cloudflare R2 secret access key.
note
Note
Permissions attribute is not supported with Cloudflare R2, if you specify it the job will fail with a saving error.

URL Structure for Cloudflare

The urlof Cloudflare R2 Storage consists of a account id, bucket and path. Check the examples for single file and ABR formats like HLS and DASH below:

s3://[account_id].r2.cloudflarestorage.com/[bucket]/[path]
Components of URL
account idYour unique Cloudflare account ID.
bucketThe name of your Cloudflare R2 storage bucket.
pathThe path within your bucket where you wish to save the file.

When saving ABR outputs like HLS or DASH, please specify the path to a folder where the contents of the HLS or DASH stream should be located:

s3://[account_id].r2.cloudflarestorage.com/[bucket]/[folder]
Components of URL
account idYour unique Cloudflare account ID.
bucketThe name of your Cloudflare R2 storage bucket.
folderThe folder within your bucket where you wish to save the HLS or DASH content.

For more information please refer to the official Cloudflare documentation.

Destination Object Example

"destination": {
  "url": "s3://123456789abcdef.r2.cloudflarestorage.com/my-bucket/folder/output.mp4",
  "key": "myAccessKeyId",
  "secret": "mySecretAccessKey"
}

When saving ABR outputs like HLS or DASH, please specify the path to a folder where the contents of the HLS or DASH stream should be located:

"destination": {
  "url": "s3://123456789abcdef.r2.cloudflarestorage.com/my-bucket/folder",
  "key": "myAccessKeyId",
  "secret": "mySecretAccessKey"
}

Considerations

S3 Compatibility: Leverage the compatibility with S3 tools and workflows.

Connectivity Issues: Verify that the account ID and bucket name in the URL are correct.

Authentication Errors: Double-check the access key ID and secret access key for accuracy.

Explore Cloudflare R2’s advanced features, such as custom domains and edge caching, for enhanced performance and scalability.