Azblob
Azure Storage Blob services support.
Capabilities
This service can be used to:
- stat
- read
- write
- append
- create_dir
- delete
- copy
- rename
- list
- presign
- blocking
Configuration
root
: Set the work dir for backend.container
: Set the container name for backend.endpoint
: Set the endpoint for backend.account_name
: Set the account_name for backend.account_key
: Set the account_key for backend.
Refer to public API docs for more information.
Examples
This example works on Azurite for local developments.
Start local blob service
docker run -p 10000:10000 mcr.microsoft.com/azure-storage/azurite
az storage container create --name test --connection-string "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;"
Init OpenDAL Operator
Via Builder
use std::sync::Arc;
use anyhow::Result;
use opendal::services::Azblob;
use opendal::Operator;
#[tokio::main]
async fn main() -> Result<()> {
// Create azblob backend builder.
let mut builder = Azblob::default();
// Set the root for azblob, all operations will happen under this root.
//
// NOTE: the root must be absolute path.
builder.root("/path/to/dir");
// Set the container name, this is required.
builder.container("test");
// Set the endpoint, this is required.
//
// For examples:
// - "http://127.0.0.1:10000/devstoreaccount1"
// - "https://accountname.blob.core.windows.net"
builder.endpoint("http://127.0.0.1:10000/devstoreaccount1");
// Set the account_name and account_key.
//
// OpenDAL will try load credential from the env.
// If credential not set and no valid credential in env, OpenDAL will
// send request without signing like anonymous user.
builder.account_name("devstoreaccount1");
builder.account_key("Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==");
// `Accessor` provides the low level APIs, we will use `Operator` normally.
let op: Operator = Operator::new(builder)?.finish();
Ok(())
}
Via Config
- Rust
- Node.js
- Python
use anyhow::Result;
use opendal::Operator;
use opendal::Scheme;
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<()> {
let mut map = HashMap::new();
map.insert("root".to_string(), "/path/to/dir".to_string());
map.insert("container".to_string(), "test".to_string());
map.insert("endpoint".to_string(), "http://127.0.0.1:10000/devstoreaccount1".to_string());
map.insert("account_name".to_string(), "devstoreaccount1".to_string());
map.insert("account_key".to_string(), "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==".to_string());
let op: Operator = Operator::via_map(Scheme::Azblob, map)?;
Ok(())
}
import { Operator } from "opendal";
async function main() {
const op = new Operator("azblob", {
root: "/path/to/dir",
container: "test",
endpoint: "http://127.0.0.1:10000/devstoreaccount1",
account_name: "devstoreaccount1",
account_key: "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
});
}
import opendal
op = opendal.Operator("azblob",
root="/path/to/dir",
container="test",
endpoint="http://127.0.0.1:10000/devstoreaccount1",
account_name="devstoreaccount1",
account_key="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
)