aliyun OSS 的一个客户端
本不想重复造轮子,但是发现官方提供的 sdk 还有优化的空间,然后就尝试着写一写,就当是练习 rust 的项目了
[dependencies]
aliyun-oss-client = "0.2.0"
``` // 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().unwrap();
println!("buckets list: {:?}", response);
let response = client.get_bucket_info().unwrap();
println!("bucket info: {:?}", response);
let response = client.get_object_list().unwrap();
println!("objects list: {:?}", response);
``` 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.putfile(&file_content, "examples/bg2015071010.png").expect("上传失败"); ```
``` client.delete_object("examples/bg2015071010.png").unwrap();
```