Skip to content

Commit

Permalink
doc: 补充文档内容
Browse files Browse the repository at this point in the history
  • Loading branch information
tu6ge committed Sep 2, 2024
1 parent 726c605 commit fa60de4
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 3 deletions.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,79 @@
详细使用案例如下:

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 buckes = client.get_buckets(&EndPoint::CN_QINGDAO).await?;

// 获取某一个 bucket 的文件列表
let objects = buckes[0].get_objects(&ObjectQuery::new(), &client).await?;

// 获取文件的详细信息
let obj_info = objects[0].get_info(&client).await?;

let object = Object::new("filename.txt");
// 上传文件
let info = object.upload("content".into(), &client).await?;
// 下载文件内容
let content = object.download(&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<MyBucket> = 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<MyObject>, _) =
buckets[0].export_objects(&condition, &client).await?;
```

# RFC

get Buckets
Expand Down
40 changes: 37 additions & 3 deletions examples/demo.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
use aliyun_oss_client::{types::ObjectQuery, Client, EndPoint};
use serde::Deserialize;

async fn run() -> Result<(), aliyun_oss_client::Error> {
let client = Client::from_env()?;

let buckes = client.get_buckets(&EndPoint::CN_QINGDAO).await?;
let buckets = client.get_buckets(&EndPoint::CN_QINGDAO).await?;

let objects = buckes[0].get_objects(&ObjectQuery::new(), &client).await?;
let objects = buckets[0].get_objects(&ObjectQuery::new(), &client).await?;

let obj_info = objects[0].get_info(&client).await?;
let _obj_info = objects[0].get_info(&client).await?;

#[derive(Debug, Deserialize)]
struct MyBucket {
Comment: String,
CreationDate: String,
ExtranetEndpoint: EndPoint,
IntranetEndpoint: String,
Location: String,
Name: String,
Region: String,
StorageClass: String,
}

let list: Vec<MyBucket> = client.export_buckets(&EndPoint::CN_QINGDAO).await?;

#[derive(Debug, Deserialize)]
struct MyBucketInfo {
Name: String,
}
let res: MyBucketInfo = buckets[0].export_info(&client).await?;

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<MyObject>, _) =
buckets[0].export_objects(&condition, &client).await?;
Ok(())
}

Expand Down

0 comments on commit fa60de4

Please sign in to comment.