Crates.io | obs-sdk |
lib.rs | obs-sdk |
version | 0.1.2 |
created_at | 2025-08-23 03:01:33.816097+00 |
updated_at | 2025-08-24 12:37:26.393053+00 |
description | 针对华为云的OBS工具封装rust版本的sdk |
homepage | |
repository | https://gitee.com/ranfusheng/obs-sdk-rust.git |
max_upload_size | |
id | 1807176 |
size | 82,733 |
针对华为云的OBS工具封装rust版本的sdk
华为obs文档:https://support.huaweicloud.com/api-obs/obs_04_0010.html
在线签名工具:https://obs-community.obs.cn-north-1.myhuaweicloud.com/sign/header_signature.html
目前已实现的API:
软件架构说明
cargo add reqwest -F "multipart,json"
cargo add tokio -F "full"
cargo add serde -F "derive"
cargo add serde_yaml serde_derive serde_json hmac sha1 base64 chrono regex md5
cargo add obs-sdk
use obs_sdk::ObsClient;
static ENDPOINT: &str = "obs.cn-north-4.myhuaweicloud.com";
static AK: &str = "YOUR_AK";
static SK: &str = "YOUR_SK";
static BUCKET_NAME: &str = "bucket_name";
#[tokio::test]
async fn test_list_prefix() -> Result<(), Box<dyn std::error::Error>> {
let client = ObsClient {
endpoint: ENDPOINT.to_string(),
ak: AK.to_string(),
sk: SK.to_string(),
bucket: BUCKET_NAME.to_string(),
};
let res = client.list("tmp").await?;
println!("{:?}", res);
Ok(())
}
use obs_sdk::ObsClient;
static ENDPOINT: &str = "obs.cn-north-4.myhuaweicloud.com";
static AK: &str = "YOUR_AK";
static SK: &str = "YOUR_SK";
static BUCKET_NAME: &str = "bucket_name";
#[tokio::test]
async fn test_upload_object() -> Result<(), Box<dyn std::error::Error>> {
let client = ObsClient {
endpoint: ENDPOINT.to_string(),
ak: AK.to_string(),
sk: SK.to_string(),
bucket: BUCKET_NAME.to_string(),
};
let res = client.upload_file("tmp_cargo.txt", "Cargo.txt").await?;
println!("{:?}", res);
Ok(())
}
use obs_sdk::ObsClient;
static ENDPOINT: &str = "obs.cn-north-4.myhuaweicloud.com";
static AK: &str = "YOUR_AK";
static SK: &str = "YOUR_SK";
static BUCKET_NAME: &str = "bucket_name";
#[tokio::test]
async fn test_download_file02() -> Result<(), Box<dyn std::error::Error>> {
let client = ObsClient {
endpoint: ENDPOINT.to_string(),
ak: AK.to_string(),
sk: SK.to_string(),
bucket: BUCKET_NAME.to_string(),
};
let res = client.download_file("2hls_stutter-10.mp4", "video/2hls_stutter-10.mp4", false).await;
res
}
use obs_sdk::ObsClient;
use std::path::Path;
use std::fs;
static ENDPOINT: &str = "obs.cn-north-4.myhuaweicloud.com";
static AK: &str = "YOUR_AK";
static SK: &str = "YOUR_SK";
static BUCKET_NAME: &str = "bucket_name";
#[tokio::test]
async fn test_download_file01() -> Result<(), Box<dyn std::error::Error>> {
let client = ObsClient {
endpoint: ENDPOINT.to_string(),
ak: AK.to_string(),
sk: SK.to_string(),
bucket: BUCKET_NAME.to_string(),
};
let data = client.download_object("2hls_stutter-10.mp4").await?;
let file_path = Path::new("output.mp4");
match fs::write(file_path, data) {
Ok(_) => println!("文件保存成功{:?}", file_path),
Err(e) => eprintln!("文件保存失败:{}", e)
}
Ok(())
}
use obs_sdk::ObsClient;
static ENDPOINT: &str = "obs.cn-north-4.myhuaweicloud.com";
static AK: &str = "YOUR_AK";
static SK: &str = "YOUR_SK";
static BUCKET_NAME: &str = "bucket_name";
#[test]
fn test_url_sign() -> Result<(), Box<dyn std::error::Error>> {
let client = ObsClient {
endpoint: ENDPOINT.to_string(),
ak: AK.to_string(),
sk: SK.to_string(),
bucket: BUCKET_NAME.to_string(),
};
let sign_url = client.url_sign("https://ranfs.obs.cn-north-4.myhuaweicloud.com/tmp_cargo.txt")?;
println!("sign_url = {}", sign_url);
Ok(())
}
Fork 本仓库
新建 Feat_xxx 分支
提交代码
新建 Pull Request