Upload files to Cloudflare R2 in the terminal with Rclone

Leon Dong
2 min readJan 17, 2023

After fighting with a particular cloud storage provider for domain name filing, I abandon their services. In the last few days, I downloaded my blog attachments, including images, shell scripts, and media files, from the tiring cloud storage. And then, I decided to use Cloudflare R2 to host my blog attachments.

Cloudflare R2

When uploading files to R2 with the web page console, I feel it’s absolutely tedious work. Since the web interface just supports 100 files within each operation. Rclone helps me accomplish the job more efficiently.

Rclone

Rclone is a command-line program to manage files on cloud storage. It’s a strong alternative to many cloud storage providers’ web interfaces.

According to the guide, I use homebrew to install rclone on my mac quickly. Although such a method affects the full features, it’s enough to manage files.

Configure Rclone

To create a rclone.conf file in the path of ~/.config/rclone/.

Contents of the conf file are as follows:

[r2]
type = s3
provider = Cloudflare
access_key_id = <ACCESS_KEY>
secret_access_key = <SECRET_ACCESS_KEY>
region = auto
endpoint = https://<ACCOUNT_ID>.r2.cloudflarestorage.com
acl = private
  • [r2]: A custom name(an alias) for storage service. We need to use it to operate files.
  • type = s3: The type of file operation API. R2 supports the S3 standard protocol.
  • provider = Cloudflare: The storage provider ID. You could use man rclone in your terminal to get the supported providers.
  • access_key_id: You need to create a token with edit permission on the R2 console.
  • secret_access_key: Same as above.
  • endpoint: The URL that rclone uses to operate files. To get the account id on the top-right of the R2 homepage.
Cloudflare R2 account id

Usage

To run rclone lsf r2: to see your buckets and rclone lsf r2:my-bucket to show the file list within a bucket.

Especially notice the last symbol `:`

To upload a file:

rclone copy /path/to/file r2:my-bucket

For more rclone commands refers to here.

--

--