#azure-storage #azure-sdk #azure #storage #blob #blobs #sdk

azure_storage_blobs

Azure Blob Storage 从 Azure SDK for Rust 的 crate

19 个重大版本发布

0.20.0 2024 年 4 月 24 日
0.19.0 2024 年 1 月 5 日
0.18.0 2023 年 12 月 11 日
0.17.0 2023 年 11 月 3 日
0.1.0 2022 年 1 月 25 日

#1 in #azure-sdk

Download history 33151/week @ 2024-04-26 25844/week @ 2024-05-03 25977/week @ 2024-05-10 28659/week @ 2024-05-17 32626/week @ 2024-05-24 42033/week @ 2024-05-31 40690/week @ 2024-06-07 30733/week @ 2024-06-14 43327/week @ 2024-06-21 38482/week @ 2024-06-28 42685/week @ 2024-07-05 39521/week @ 2024-07-12 41308/week @ 2024-07-19 42608/week @ 2024-07-26 39081/week @ 2024-08-02 40726/week @ 2024-08-09

170,121 monthly downloads
用于 14 个 crates (12 直接)

MIT 许可证

6MB
104K SLoC

azure_storage_blobs

此 crate 来自 Azure SDK for Rust。它支持 Azure Blob Storage

示例


use azure_core::error::{ErrorKind, ResultExt};
use azure_storage::prelude::*;
use azure_storage_blobs::prelude::*;
use futures::stream::StreamExt;

#[tokio::main]
async fn main() -> azure_core::Result<()> {
    let file_name = "azure_sdk_for_rust_stream_test.txt";

    // First we retrieve the account name and access key from environment variables.
    let account = std::env::var("STORAGE_ACCOUNT").expect("missing STORAGE_ACCOUNT");
    let access_key = std::env::var("STORAGE_ACCESS_KEY").expect("missing STORAGE_ACCOUNT_KEY");
    let container = std::env::var("STORAGE_CONTAINER").expect("missing STORAGE_CONTAINER");
    let blob_name = std::env::var("STORAGE_BLOB_NAME").expect("missing STORAGE_BLOB_NAME");

    let storage_credentials = StorageCredentials::access_key(account.clone(), access_key);
    let blob_client = ClientBuilder::new(account, storage_credentials).blob_client(&container, blob_name);

    blob_client.put_block_blob("hello world").content_type("text/plain").await?;

    let mut result: Vec<u8> = vec![];

    // The stream is composed of individual calls to the get blob endpoint
    let mut stream = blob_client.get().into_stream();
    while let Some(value) = stream.next().await {
        let mut body = value?.data;
        // For each response, we stream the body instead of collecting it all
        // into one large allocation.
        while let Some(value) = body.next().await {
            let value = value?;
            result.extend(&value);
        }
    }

    println!("result: {:?}", result);

    Ok(())
}

许可证:MIT

依赖项

~8–23MB
~341K SLoC