Unofficial Cloudflare R2 SDK
This is the "Unofficial Cloudflare R2 SDK".
It can upload, download, and delete binary data or files to Cloudflare R2.
This crate is based on cloudflare-r2-rs (License: Apache-2.0, Owner: milen-denev) and r2sync (License: MIT, Owner: Songmu).
[!TIP] date: 2025-11-07
The v. 3.2.0 was removed the following S3Client config.
The following options were added to resolve this problem. However, since I confirmed it functions correctly without these options, I have removed them.
requestChecksumCalculation: "WHEN_REQUIRED", responseChecksumValidation: "WHEN_REQUIRED",
News
-
2025-3-2 (JST): ver. 3.1.0 Release!
-
2025-2-25 (JST): ver. 3.0.3 Release!
-
2025-2-19 (JST): ver. 3.0.0 Release!
This crates is solved this problem by adding the following S3Client config.
requestChecksumCalculation: "WHEN_REQUIRED", responseChecksumValidation: "WHEN_REQUIRED",Reference: https://developers.cloudflare.com/r2/examples/aws/aws-sdk-js-v3/
Documentation
https://docs.rs/cf-r2-sdk/latest/cf_r2_sdk/
Article (Japanese)
https://qiita.com/Yuuki-Osada/items/10734e3d701a519b3d5f
DeepWiki
[!WARNING] The accuracy of the contents of generated deepwiki has not been verified by me.
I recommend that you look at the documentation at docs.rs.
https://deepwiki.com/Myxogastria0808/cf-r2-sdk
How to use
1. Create a aws_sdk_s3::Client object
Set the "bucket name", "access key id", "secret access key", "endpoint url", and "region".
Default value of region is "auto" (region is option field).
// create a client object
let object: = new
.set_bucket_name
.set_access_key_id
.set_secret_access_key
.set_endpoint
.set_region
.create_client_result;
2. Operate R2 object strage
upload binary data
let _ = object
.upload_binary
.await.unwrap;
upload file
let _ = object
.upload_file
.await.unwrap;
download binary data
let binany: = object.download.await.unwrap;
delete file
let _ = object.delete.await.unwrap;
get file names vector (max get file names is 10)
let file_names_list: = object.list_objects.await.unwrap;
Example
https://github.com/Myxogastria0808/cf-r2-sdk/blob/main/examples/simple.rs
use Builder;
use Error;
use dotenv;
use env;
async