aliyun OSS 的一个客户端
最开始的时候,是作为一个 rust 练手项目,渐渐的现在越来越完善了,包含了 rust 的 struct,enum, async, trait features 等特性, 以及自定义 error 类,同时也包含完整的的测试用例
[dependencies]
aliyun-oss-client = "^0.7"
``` // dotenv 是用于获取配置信息的,可以不使用 extern crate dotenv; use dotenv::dotenv; use std::env;
// 需要提供四个配置信息 let keyid = env::var("ALIYUNKEYID").unwrap(); let keysecret = env::var("ALIYUNKEYSECRET").unwrap(); let endpoint = env::var("ALIYUNENDPOINT").unwrap(); let bucket = env::var("ALIYUNBUCKET").unwrap();
// 获取客户端实例 let client = aliyunossclient::client(&keyid,&keysecret, &endpoint, &bucket); ```
let response = client.get_bucket_list().await.unwrap();
println!("buckets list: {:?}", response);
let response = client.get_bucket_info().await.unwrap();
println!("bucket info: {:?}", response);
let query: HashMap<String,String> = HashMap::new();
let response = client.get_object_list(query).await.unwrap();
println!("objects list: {:?}", response);
```
let mut query:HashMap
let result = client.getbucketinfo().await.unwrap().getobjectlist(query).await.unwrap();
println!("object list : {:?}", result);
```
``` client.put_file("examples/bg2015071010.png", "examples/bg2015071010.png").expect("上传失败");
// or 上传文件内容 let mut filecontent = Vec::new(); std::fs::File::open(filename) .expect("open file failed").readtoend(&mut filecontent) .expect("readtoend failed"); client.putcontent(&file_content, "examples/bg2015071010.png").await.expect("上传失败"); ```
client.delete_object("examples/bg2015071010.png").await.unwrap();
如需使用,需要启用
blocking
特征
let response = client.blocking_get_bucket_list().unwrap();
println!("buckets list: {:?}", response);
let response = client.blocking_get_bucket_info().unwrap();
println!("bucket info: {:?}", response);
let query: HashMap<String,String> = HashMap::new();
let response = client.blocking_get_object_list(query).unwrap();
println!("objects list: {:?}", response);
```
let mut query:HashMap
let result = client.blockinggetbucketinfo().unwrap().blockinggetobjectlist(query).unwrap();
println!("object list : {:?}", result);
// 翻页功能 获取下一页数据 println!("next object list: {:?}", result.next().unwrap()); ```
``` client.blockingputfile("examples/bg2015071010.png", "examples/bg2015071010.png").expect("上传失败");
// or 上传文件内容 let mut filecontent = Vec::new(); std::fs::File::open(filename) .expect("open file failed").readtoend(&mut filecontent) .expect("readtoend failed"); client.blockingputcontent(&filecontent, "examples/bg2015071010.png").expect("上传失败"); ```
``` client.blockingdeleteobject("examples/bg2015071010.png").unwrap();
```