#object-storage #cloud-storage #storage-api #cloudflare #file-upload #s3 #storage-service

cloudflare-r2-rs

A package which provides dead simple APIs to work with Cloudflare R2 and OVH Object Storage

13 releases (5 breaking)

new 0.6.8 Dec 6, 2024
0.6.7 Nov 6, 2024
0.6.6 Oct 8, 2024
0.6.2 Jul 7, 2024
0.1.0 Mar 13, 2024

#767 in Network programming

Download history 212/week @ 2024-08-26 295/week @ 2024-09-02 83/week @ 2024-09-09 63/week @ 2024-09-16 100/week @ 2024-09-23 193/week @ 2024-09-30 218/week @ 2024-10-07 198/week @ 2024-10-14 83/week @ 2024-10-21 6/week @ 2024-10-28 217/week @ 2024-11-04 28/week @ 2024-11-11 35/week @ 2024-11-18 14/week @ 2024-11-25 115/week @ 2024-12-02

205 downloads per month

Apache-2.0

16KB
183 lines

Easy to use Rust API for Cloudflare's R2 service

Simple Rust API for Cloudflare's R2 and OVH Object Storage (possibly others as well but not tested) with create_bucket, delete_bucket and upload, get, delete file operations. Production ready since it's a thin layer above AWS SDK S3. Updated to be using latest versions.

cargo.toml

[dependencies]
cloudflare-r2-rs = "0.6.8"

example use


//Cloudflare
let r2_manager = R2Manager::new(
    //Bucket Name
    "my-bucket", 
    //Cloudflare URI endpoint
    "https://some-id-55353-53535.r2.cloudflarestorage.com",
    //API Token's Access Key ID
    "some-id-55353-53535",
    //API Token's Secret Access Key
    "some-long-secret-key-55353-53535-55353-53535"
).await;

//OVH
let _r2_manager2 = R2Manager::new_with_region(
    "bucket-name", 
    "https://s3.<region>.io.cloud.ovh.net",
    "some-id-55353-53535",
    "some-secret-55353-53535",
    "<region>").await;

//Gives control to set Cache-Control header and Content-Type header
r2_manager.upload("test", b"Hello world", Some("max-age=60"), Some("text/plain")).await;
let bytes = r2_manager.get("test").await.unwrap();
println!("{}", String::from_utf8(bytes).unwrap());

Dependencies

~32MB
~410K SLoC