aliyun OSS 的一个异æ¥/åŒæ¥å®¢æˆ·ç«¯ï¼ŒåŒ…å«ä»¥ä¸‹åŠŸèƒ½ï¼š
auth
模å—ï¼Œå¤„ç† OSS 验è¯ï¼Œå¯ä»¥æŠ½ç¦»å‡ºæ¥ï¼Œç‹¬ç«‹ä¸Ž reqwest
库é…åˆä½¿ç”¨traits
模å—ï¼ŒåŒ…å« OSS 接å£è¿”回的原始 xml
æ•°æ®çš„解æžæ–¹å¼ï¼Œå¯ä»¥å°†æ•°æ®æ–¹ä¾¿çš„导入到自定义的 rust 类型ä¸ï¼Œå¯ä»¥ç‹¬ç«‹ä½¿ç”¨client
模å—,基础部分,å°è£…了 reqwest
auth
模å—,并æ供了一些便æ·æ–¹æ³•bucket
模å—ï¼ŒåŒ…å« bucket 以åŠå…¶åˆ—表的结构体object
模å—ï¼ŒåŒ…å« object 以åŠå…¶åˆ—表的结构体file
模å—ï¼Œæ–‡ä»¶ä¸Šä¼ ï¼Œä¸‹è½½ï¼Œåˆ é™¤ç‰åŠŸèƒ½ï¼Œå¯åœ¨ client, bucket, object ç‰ç»“构体ä¸å¤ç”¨config
模å—,OSS é…置信æ¯ï¼Œå¯ç”¨äºŽä»Žæ•°æ®åº“读å–é…ç½®ç‰æ“作toml
[dependencies]
aliyun-oss-client = "[last_version]"
rust
use std::env::set_var;
set_var("ALIYUN_KEY_ID", "foo1");
set_var("ALIYUN_KEY_SECRET", "foo2");
set_var("ALIYUN_ENDPOINT", "qingdao");
set_var("ALIYUN_BUCKET", "foo4");
let client = aliyun_oss_client::Client::from_env();
或者
rust
let client = aliyun_oss_client::Client::new("key1".into(), "secret1".into(), "qingdao".into(), "my-bucket".into());
或者
rust
let client = aliyun_oss_client::client("key1", "secret1", "qingdao", "my-bucket");
在阿里云的 ECS 上请求 OSS 接å£ï¼Œä½¿ç”¨å†…网 API 有更高的效率,åªéœ€è¦åœ¨ ECS 上设置 ALIYUN_OSS_INTERNAL
环境å˜é‡ä¸º true
å³å¯
```rust
# use std::env::set_var;
# set_var("ALIYUN_KEY_ID", "foo1");
# set_var("ALIYUN_KEY_SECRET", "foo2");
# set_var("ALIYUN_ENDPOINT", "qingdao");
# set_var("ALIYUN_BUCKET", "foo4");
# let client = aliyun_oss_client::Client::from_env().unwrap();
client.get_bucket_list().await;
```
```rust
# use std::env::set_var;
# set_var("ALIYUN_KEY_ID", "foo1");
# set_var("ALIYUN_KEY_SECRET", "foo2");
# set_var("ALIYUN_ENDPOINT", "qingdao");
# set_var("ALIYUN_BUCKET", "foo4");
# let client = aliyun_oss_client::Client::from_env().unwrap();
let response = client.get_bucket_info().await;
println!("bucket info: {:?}", response);
```
```rust
# use std::env::set_var;
# set_var("ALIYUN_KEY_ID", "foo1");
# set_var("ALIYUN_KEY_SECRET", "foo2");
# set_var("ALIYUN_ENDPOINT", "qingdao");
# set_var("ALIYUN_BUCKET", "foo4");
# let client = aliyun_oss_client::Client::from_env().unwrap();
let response = client.get_object_list([]).await;
println!("objects list: {:?}", response);
```
```ignore
# use std::env::set_var;
# set_var("ALIYUN_KEY_ID", "foo1");
# set_var("ALIYUN_KEY_SECRET", "foo2");
# set_var("ALIYUN_ENDPOINT", "qingdao");
# set_var("ALIYUN_BUCKET", "foo4");
# let client = aliyun_oss_client::Client::from_env().unwrap();
use aliyun_oss_client::QueryKey;
let result = client.get_bucket_info().await.unwrap().get_object_list([
(QueryKey::MaxKeys, 5u8.into()),
(QueryKey::Prefix, "babel".into()),
]).await;
println!("object list : {:?}", result);
```
```rust
# use std::env::set_var;
# set_var("ALIYUN_KEY_ID", "foo1");
# set_var("ALIYUN_KEY_SECRET", "foo2");
# set_var("ALIYUN_ENDPOINT", "qingdao");
# set_var("ALIYUN_BUCKET", "foo4");
# let client = aliyun_oss_client::Client::from_env().unwrap();
use aliyun_oss_client::file::File;
client
.put_file("examples/bg2015071010.png", "examples/bg2015071010.png")
.await;
// or ä¸Šä¼ æ–‡ä»¶å†…å®¹
let file_content = std::fs::read("examples/bg2015071010.png").unwrap();
client
.put_content(file_content, "examples/bg2015071010.png", |_| {
Some("image/png")
})
.await;
// or è‡ªå®šä¹‰ä¸Šä¼ æ–‡ä»¶ Content-Type
let file_content = std::fs::read("examples/bg2015071010.png").unwrap();
client
.put_content_base(file_content, "image/png", "examples/bg2015071010.png")
.await;
```
```rust
# use std::env::set_var;
# set_var("ALIYUN_KEY_ID", "foo1");
# set_var("ALIYUN_KEY_SECRET", "foo2");
# set_var("ALIYUN_ENDPOINT", "qingdao");
# set_var("ALIYUN_BUCKET", "foo4");
# let client = aliyun_oss_client::Client::from_env().unwrap();
use aliyun_oss_client::file::File;
client.delete_object("examples/bg2015071010.png").await;
```
如需使用,需è¦å¯ç”¨
blocking
特å¾
```ignore // dotenv 是用于获å–é…置信æ¯çš„,å¯ä»¥ä¸ä½¿ç”¨ extern crate dotenv; use dotenv::dotenv; use std::env;
// 需è¦æ供四个é…ç½®ä¿¡æ¯ use aliyunossclient::BucketName; let bucket = BucketName::new("bbb").unwrap(); // 获å–客户端实例 let client = aliyunossclient::ClientRc::new("key1".into(), "secret1".into(), "qingdao".into(), bucket); ```
```ignore
let response = client.getbucketlist(); println!("buckets list: {:?}", response); ```
```ignore
let response = client.getbucketinfo(); println!("bucket info: {:?}", response); ```
```ignore
let response = client.getobjectlist([]); println!("objects list: {:?}", response); ```
```ignore
use aliyunossclient::QueryKey;
let mut result = client.getbucketinfo().unwrap().getobjectlist([ (QueryKey::MaxKeys, 5u8.into()), (QueryKey::Prefix, "babel".into()), ]).unwrap();
println!("object list : {:?}", result);
// 翻页功能 获å–ä¸‹ä¸€é¡µæ•°æ® println!("next object list: {:?}", result.next()); ```
```ignore
use aliyunossclient::file::blocking::File; client .put_file("examples/bg2015071010.png", "examples/bg2015071010.png");
// or ä¸Šä¼ æ–‡ä»¶å†…å®¹ let filecontent = std::fs::read("examples/bg2015071010.png").unwrap(); client .putcontent(filecontent, "examples/bg2015071010.png", || { Some("image/png") });
// or è‡ªå®šä¹‰ä¸Šä¼ æ–‡ä»¶ Content-Type let filecontent = std::fs::read("examples/bg2015071010.png").unwrap(); client .putcontentbase(filecontent, "image/png", "examples/bg2015071010.png"); ```
```ignore
use aliyunossclient::file::blocking::File; client.delete_object("examples/bg2015071010.png"); ```
bash
rustup run nightly cargo bench
bash
conventional-changelog -p angular -i Changelog.md -s
欢迎å„ç§ PR 贡献