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-01-18
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
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: Operator = new
.set_bucket_name
.set_access_key_id
.set_secret_access_key
.set_endpoint
.set_region
.create_client;
2. Operate R2 object strage
upload binary data
let _ = object
.upload_binary
.await;
upload file
let _ = object
.upload_file
.await;
download binary data
let binany: = object.download.await;
delete file
let _ = object.delete.await;
Sample
Sample repository is
https://github.com/Myxogastria0808/cf-r2-sdk-sample .
use Builder;
use dotenv;
use env;
async