home / skills / sickn33 / antigravity-awesome-skills / azure-storage-blob-rust

azure-storage-blob-rust skill

/skills/azure-storage-blob-rust

This skill helps you manage Azure Blob Storage in Rust by guiding uploading, downloading, and managing containers with best practices.

npx playbooks add skill sickn33/antigravity-awesome-skills --skill azure-storage-blob-rust

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
3.2 KB
---
name: azure-storage-blob-rust
description: |
  Azure Blob Storage SDK for Rust. Use for uploading, downloading, and managing blobs and containers.
  Triggers: "blob storage rust", "BlobClient rust", "upload blob rust", "download blob rust", "container rust".
package: azure_storage_blob
---

# Azure Blob Storage SDK for Rust

Client library for Azure Blob Storage — Microsoft's object storage solution for the cloud.

## Installation

```sh
cargo add azure_storage_blob azure_identity
```

## Environment Variables

```bash
AZURE_STORAGE_ACCOUNT_NAME=<storage-account-name>
# Endpoint: https://<account>.blob.core.windows.net/
```

## Authentication

```rust
use azure_identity::DeveloperToolsCredential;
use azure_storage_blob::{BlobClient, BlobClientOptions};

let credential = DeveloperToolsCredential::new(None)?;
let blob_client = BlobClient::new(
    "https://<account>.blob.core.windows.net/",
    "container-name",
    "blob-name",
    Some(credential),
    Some(BlobClientOptions::default()),
)?;
```

## Client Types

| Client | Purpose |
|--------|---------|
| `BlobServiceClient` | Account-level operations, list containers |
| `BlobContainerClient` | Container operations, list blobs |
| `BlobClient` | Individual blob operations |

## Core Operations

### Upload Blob

```rust
use azure_core::http::RequestContent;

let data = b"hello world";
blob_client
    .upload(
        RequestContent::from(data.to_vec()),
        false,  // overwrite
        u64::try_from(data.len())?,
        None,
    )
    .await?;
```

### Download Blob

```rust
let response = blob_client.download(None).await?;
let content = response.into_body().collect_bytes().await?;
println!("Content: {:?}", content);
```

### Get Blob Properties

```rust
let properties = blob_client.get_properties(None).await?;
println!("Content-Length: {:?}", properties.content_length);
```

### Delete Blob

```rust
blob_client.delete(None).await?;
```

## Container Operations

```rust
use azure_storage_blob::BlobContainerClient;

let container_client = BlobContainerClient::new(
    "https://<account>.blob.core.windows.net/",
    "container-name",
    Some(credential),
    None,
)?;

// Create container
container_client.create(None).await?;

// List blobs
let mut pager = container_client.list_blobs(None)?;
while let Some(blob) = pager.try_next().await? {
    println!("Blob: {}", blob.name);
}
```

## Best Practices

1. **Use Entra ID auth** — `DeveloperToolsCredential` for dev, `ManagedIdentityCredential` for production
2. **Specify content length** — required for uploads
3. **Use `RequestContent::from()`** — to wrap upload data
4. **Handle async operations** — use `tokio` runtime
5. **Check RBAC permissions** — ensure "Storage Blob Data Contributor" role

## RBAC Permissions

For Entra ID auth, assign one of these roles:
- `Storage Blob Data Reader` — read-only
- `Storage Blob Data Contributor` — read/write
- `Storage Blob Data Owner` — full access including RBAC

## Reference Links

| Resource | Link |
|----------|------|
| API Reference | https://docs.rs/azure_storage_blob |
| Source Code | https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/storage/azure_storage_blob |
| crates.io | https://crates.io/crates/azure_storage_blob |

Overview

This skill provides a Rust client for Azure Blob Storage, enabling uploading, downloading, and managing blobs and containers. It exposes BlobServiceClient, BlobContainerClient, and BlobClient for account, container, and blob-level operations. Use it to integrate Azure object storage into Rust applications with async support and Entra ID authentication.

How this skill works

The SDK constructs clients pointing at your storage account endpoint and authenticates using credentials like DeveloperToolsCredential or ManagedIdentityCredential. You can upload data with RequestContent::from(), download and collect bytes, query properties, delete blobs, and enumerate container contents using async methods and paged iterators. It expects explicit content-length for uploads and runs inside a Tokio runtime.

When to use it

  • Uploading or downloading large or small binary files from a Rust service or CLI.
  • Integrating Rust applications with Azure for backups, static asset hosting, or data pipelines.
  • Managing blob lifecycle: list blobs, check properties, delete or overwrite content.
  • Building serverless or containerized Rust apps that use Entra ID or managed identity auth.
  • Automating storage tasks from local development to production using async code.

Best practices

  • Prefer Entra ID credentials: DeveloperToolsCredential for dev and ManagedIdentityCredential in production.
  • Always specify content-length when uploading to avoid errors and improve performance.
  • Wrap upload payloads with RequestContent::from() to ensure correct request behavior.
  • Run SDK calls under a Tokio async runtime and handle retries or transient failures.
  • Assign least-privilege RBAC roles like Storage Blob Data Contributor for write operations.

Example use cases

  • A CLI tool in Rust that uploads build artifacts to a blob container for distribution.
  • A web service that streams blobs to clients by downloading content and forwarding bytes.
  • A background worker that lists blobs to reconcile metadata or implement retention policies.
  • CI pipelines that push test results or coverage reports to Azure Blob Storage.
  • Edge services using managed identity to write sensor data directly into a storage account.

FAQ

How do I authenticate for local development?

Use DeveloperToolsCredential for interactive development and set AZURE_STORAGE_ACCOUNT_NAME with your account endpoint.

Do uploads require a content length?

Yes. Provide the content length when calling upload to comply with the SDK and service expectations.