8 个版本 (5 个破坏性更新)
0.6.2 | 2024 年 7 月 7 日 |
---|---|
0.6.1 | 2024 年 7 月 3 日 |
0.6.0 | 2024 年 6 月 18 日 |
0.5.0 | 2024 年 6 月 17 日 |
0.1.0 | 2024 年 3 月 13 日 |
#708 in 网页编程
每月 506 次下载
15KB
183 行
易于使用的 Cloudflare R2 服务的 Rust API
简单的 Rust API,用于 Cloudflare 的 R2 和 OVH 对象存储(可能还有其他服务,但未测试),包括 创建存储桶、删除存储桶 和 上传、获取、删除 文件操作。由于它是 AWS SDK S3 之上的薄层,因此已准备好用于生产。已更新到最新版本。
cargo.toml
[dependencies]
cloudflare-r2-rs = "0.6.2"
示例使用
//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());
依赖项
~27MB
~423K SLoC