https://github.com/tu6ge/oss-rs
一个阿里云 OSS 的 rust 客户端
https://github.com/tu6ge/oss-rs
aliyun aliyun-oss aliyun-rust aliyun-sdk rust-sdk
Last synced: 8 months ago
JSON representation
一个阿里云 OSS 的 rust 客户端
- Host: GitHub
- URL: https://github.com/tu6ge/oss-rs
- Owner: tu6ge
- Created: 2022-05-15T12:57:08.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2025-09-06T15:10:54.000Z (10 months ago)
- Last Synced: 2025-11-12T21:33:39.343Z (8 months ago)
- Topics: aliyun, aliyun-oss, aliyun-rust, aliyun-sdk, rust-sdk
- Language: Rust
- Homepage:
- Size: 1.54 MB
- Stars: 44
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# aliyun_oss_client 打算采用一种全新的方式来实现
**巨大更新,之前使用过的,慎重升级 0.13**
目前的实现,代码将大大简化,api 接口也更加起清晰,使用了有限的 rust 语言特性,所以接口更加统一,
大大减少了外部依赖
> 使用本 lib 创建的 oss 命令行工具:[tu6ge/oss-cli](https://github.com/tu6ge/oss-cli),也算是本库的一个演示项目
详细使用案例如下:
1. 基本操作
```rust
use aliyun_oss_client::{types::ObjectQuery, Client, EndPoint};
async fn run() -> Result<(), aliyun_oss_client::Error> {
let client = Client::from_env()?;
// 获取 buckets 列表
let buckets = client.get_buckets(&EndPoint::CN_QINGDAO).await?;
// 获取某一个 bucket 的文件列表
let objects = buckets[0]
.clone()
//.object_query(ObjctQuery::new())
.get_objects(&client).await?;
// 获取第二页数据
let second_objects = objects.next_list(&client).await?;
// 获取文件的详细信息
let obj_info = objects[0].get_info(&client).await?;
// 上传文件
let res = Object::new("abc2.txt")
.content("aaab".into())
.content_type("text/plain;charset=utf-8")
.upload(&client)
.await?;
// 使用文件句柄上传文件
let mut f = File::open("example_file.txt").unwrap();
let info = Object::new("abc_file.txt")
.file(&mut f)?
.content_type("text/plain;charset=utf-8")
.upload(&client)
.await?;
// 使用文件路径上传文件
let info = Object::new("abc_file.txt")
.file_path("example_file.txt")?
.content_type("text/plain;charset=utf-8")
.upload(&client)
.await?;
// 下载文件内容
let content = object.download(&client).await?;
// 复制文件
let res = Object::new("new_file.txt")
.copy_source("/bucket_name/source_file.txt")
.content_type("text/plain;charset=utf-8")
.copy(&client)
.await?;
// 分片上传(大文件)
let result = PartsUpload::new("myvideo23.mov")
.file_path("./video.mov".into())
.upload(&client)
.await;
// 删除文件
let result = Object::new("abc.txt")
.delete(&client)
.await;
Ok(())
}
```
2. 导出 bucket 到自定义类型
```rust
#[derive(Debug, Deserialize)]
struct MyBucket {
Comment: String,
CreationDate: String,
ExtranetEndpoint: EndPoint,
IntranetEndpoint: String,
Location: String,
Name: String,
Region: String,
StorageClass: String,
}
let list: Vec = client.export_buckets(&EndPoint::CN_QINGDAO).await?;
```
3. 导出 bucket 详细信息到自定义类型
```rust
#[derive(Debug, Deserialize)]
struct MyBucketInfo {
Name: String,
}
let res: MyBucketInfo = buckets[0].export_info(&client).await?;
```
4. 导出 object 列表到自定义
```rust
let condition = {
let mut map = ObjectQuery::new();
map.insert(ObjectQuery::MAX_KEYS, "5");
map
};
#[derive(Debug, Deserialize)]
struct MyObject {
Key: String,
}
let (list, next_token): (Vec, _) =
buckets[0].export_objects(&condition, &client).await?;
```
# RFC
get Buckets
```rust
struct Client {
key: String,
secret: String,
}
impl Client {
async fn get_buckets(&self, endpoint: EndPoint) -> Vec {
todo!()
}
// 导出到自定义的类型
pub async fn export_buckets(
&self,
endpoint: &EndPoint,
) -> Result, OssError> {
//...
}
}
```
get bucket info;
```rust
struct Bucket {
name: String,
endpoint: EndPoint,
}
impl Bucket{
async fn get_info(&self, client: &Client) -> BucketInfo {
todo!()
}
// 导出到自定义的类型
pub async fn export_info(&self, client: &Client) -> Result {
//...
}
async fn get_object(&self, client: &Client) -> Vec {
todo!()
}
// 导出到自定义的类型
pub async fn export_objects(
&self,
query: &ObjectQuery,
client: &Client,
) -> Result<(Vec, NextContinuationToken), OssError> {
//...
}
}
```
get object info
```rust
struct Object {
bucket: Bucket,
path: ObjectPath,
}
impl Object {
async fn get_info(&self, client: &Client) -> ObjectInfo {
todo!()
}
async fn upload(&self, client: &Client, content: Vec) -> Result<(), Error>{
todo!()
}
async fn download(&self, client: &Client) -> Result, Error>{
todo!()
}
}
```