Crates.io | upyun-sdk |
lib.rs | upyun-sdk |
version | 0.1.5 |
source | src |
created_at | 2024-01-04 18:03:20.276208 |
updated_at | 2024-04-16 14:17:05.245472 |
description | Upyun sdk for rust. |
homepage | https://docs.rs/upyun-sdk |
repository | https://github.com/hi-liyan/upyun-sdk |
max_upload_size | |
id | 1088863 |
size | 32,496 |
又拍云存储 Rust SDK,基于 又拍云存储 HTTP REST API 接口 和 又拍云云处理文档 开发。
[dependencies]
upyun-sdk = "0.1.3"
fn main() {
let upyun = UpYun::builder()
.bucket("service_name") // 必须
.operator("user") // 必须
.password("123456") // 必须
.timeout(30000) // 请求超时时间,可选,默认30s
.endpoint(Endpoint::Auto) // 接入点,可选,默认为自动识别接入点
.danger_accept_invalid_certs(false) // 忽略证书验证,可选,默认为 false
.build();
}
async fn main() {
let usage: u64 = upyun.usage().await.unwrap();
}
async fn main() {
upyun.mkdir("/rust").await.unwrap();
}
path 可以是目录或文件路径,如果是目录,只允许删除空的目录,否则删除请求会被拒绝。
async fn main() {
upyun.rm("/rust").await.unwrap();
}
async fn main() {
let info: FileInfo = upyun.file_info("/rust/image.png").await.unwrap();
}
async fn main() {
// 参数可选
let params = ListDirParams {
x_list_iter: None,
x_list_limit: Some(2),
x_list_order: Some("desc".to_string())
};
let dir_list = upyun.list_dir("/rust", Some(params)).await.unwrap();
}
同一个 bucket
下复制文件。并且它只能操作文件,不能操作文件夹。
async fn main() {
let params = CopyParams {
source_path: "/rust/image.jpg".to_string(),
x_upyun_metadata_directive: None,
content_md5: None
};
upyun.copy_file("/rust/image_copy.jpg", ¶ms).await.unwrap();
}
该操作可以实现文件重命名、文件移动。同一个 bucket
下移动文件,它只能操作文件,不能操作文件夹。
async fn main() {
let params = MoveParams {
source_path: "/rust/image.jpg".to_string(),
x_upyun_metadata_directive: None,
content_md5: None
};
upyun.move_file("/rust/1/image.jpg", ¶ms).await.unwrap();
}
async fn main() {
let bytes: Vec<u8> = upyun.download("/rust/image.jpg").await.unwrap();
let path = Path::new("./image.jpg");
let mut file = File::create(path).unwrap();
file.write_all(&bytes).unwrap();
}
async fn main() {
let file: Vec<u8> = read_file_to_vec("./image.jpg").unwrap();
// 可选参数
let params = UploadParams {
content_type: None,
content_md5: None,
content_secret: None,
x_upyun_meta_x: None,
x_upyun_meta_ttl: None,
x_gmkerl_thumb: None,
};
upyun.upload("/rust/1/image.jpg", file, Some(params)).await.unwrap()
}