#obs #sdk #huaweicloud

huaweicloud-sdk-rust-obs

huaweicloud obs rust sdk

11 releases

0.2.2 Aug 11, 2023
0.2.1 Jun 21, 2023
0.1.8 Jun 15, 2023

#11 in #obs

Download history 39/week @ 2024-07-24 11/week @ 2024-07-31 2/week @ 2024-09-18 3/week @ 2024-09-25

106 downloads per month

Custom license

69KB
1K SLoC

Huaweicloud OBS SDK (unofficial)

Crates.io Crates.io docs.rs

WIP. 计划只支持基本的 obs 操作。

基本使用

  1. 添加 sdk 到项目中:
cargo add huaweicloud-sdk-rust-obs

2.示例

#[tokio::main]
async fn main() -> Result<(), ObsError> {
    const DEFAULT_BUCKET_NAME:&str = "test_bucket";
    let endpoint = "https://obs.ap-southeast-1.myhuaweicloud.com";
    // see: https://support.huaweicloud.com/api-obs/obs_04_0116.html
    let ak = "xxx"; 
    let sk = "xxxxxx";
    let obs = client::Client::builder()
        .endpoint(endpoint)
        .security_provider(ak, sk)
        .build()?;

    // put object
    let object = include_bytes!("testdata/test.jpeg");
    obs.put_object(DEFAULT_BUCKET_NAME, "obs-client-key.jpeg", object)
        .await?;

    Ok(())

}

测试

  1. 在项目根目录添加 .env文件,内容格式如下:
OBS_AK=XXXXXXXXXXXXXXX
OBS_SK=XXXXXXXXXXXXXXXXXXXX
  1. tests/common/mod.rs 下的 DEFAULT_BUCKET_NAME 替换为自己的 bucket 名称
  2. 运行 cargo test

Dependencies

~8–21MB
~292K SLoC