Azure Blob Storage Management

📦

Overview

This section provides comprehensive documentation and API references for managing Azure Blob Storage using the Microsoft Azure SDKs and REST APIs. Azure Blob Storage is Microsoft's object storage solution for the cloud. Blob storage is optimized for storing massive amounts of unstructured data, such as text or binary data.

Key features include:

⚙️

Core Concepts

Storage Accounts

A storage account provides a unique namespace in Azure for your data object. All objects that you add to Azure Storage have their addresses that include your unique account name. You can manage your storage accounts through the Azure portal, Azure CLI, PowerShell, or SDKs.

Containers

A container is a logical grouping of blobs. You can think of a container as a folder in the file system.

Blobs

Blobs can be any type of text or binary data, such as images, documents, streaming media, or application data. There are three types of blobs:

🌐

SDKs & REST APIs

Access and manage Azure Blob Storage programmatically using various SDKs or the REST API.

Azure Blob Storage JavaScript SDK

Manage blobs with the powerful and convenient JavaScript SDK.

Uploading a Blob

Method: uploadBlob()

Description: Uploads a block blob to the container.


import { BlobServiceClient } from "@azure/storage-blob";

async function uploadBlob(accountName, containerName, blobName, data) {
    const blobServiceClient = new BlobServiceClient(`https://${accountName}.blob.core.windows.net`);
    const containerClient = blobServiceClient.getContainerClient(containerName);
    const blockBlobClient = containerClient.getBlockBlobClient(blobName);

    await blockBlobClient.upload(data, data.length);
    console.log(`Blob "${blobName}" uploaded successfully.`);
}

// Example usage:
// uploadBlob("your_storage_account_name", "mycontainer", "myblob.txt", "Hello Azure Blob Storage!");
                        

Listing Blobs

Method: listBlobsFlat()

Description: Lists all blobs in a container.


async function listBlobs(accountName, containerName) {
    const blobServiceClient = new BlobServiceClient(`https://${accountName}.blob.core.windows.net`);
    const containerClient = blobServiceClient.getContainerClient(containerName);

    for await (const blobItem of containerClient.listBlobsFlat()) {
        console.log(`Blob: ${blobItem.name}`);
    }
}

// Example usage:
// listBlobs("your_storage_account_name", "mycontainer");
                        

Azure Blob Storage Python SDK

Interact with Blob Storage using the Python SDK.

Uploading a Blob

Method: upload_blob()

Description: Uploads data to a blob.


from azure.storage.blob import BlobServiceClient

def upload_blob(connect_str, container_name, blob_name, data):
    blob_service_client = BlobServiceClient.from_connection_string(connect_str)
    container_client = blob_service_client.get_container_client(container_name)
    container_client.upload_blob(name=blob_name, data=data)
    print(f"Blob '{blob_name}' uploaded successfully.")

# Example usage:
# connection_string = "YOUR_CONNECTION_STRING"
# upload_blob(connection_string, "mycontainer", "myblob.txt", "Hello Azure Blob Storage!")
                        

Downloading a Blob

Method: download_blob()

Description: Downloads the content of a blob.


def download_blob(connect_str, container_name, blob_name):
    blob_service_client = BlobServiceClient.from_connection_string(connect_str)
    container_client = blob_service_client.get_container_client(container_name)
    blob_client = container_client.get_blob_client(blob_name)
    download_stream = blob_client.download_blob()
    data = download_stream.readall()
    print(f"Blob '{blob_name}' downloaded: {data.decode('utf-8')}")

# Example usage:
# download_blob(connection_string, "mycontainer", "myblob.txt")
                        

Azure Blob Storage REST API

Directly interact with Blob Storage using HTTP requests.

Put Blob (Upload)

Request: PUT https://.blob.core.windows.net//

Headers:

  • x-ms-version: 2020-08-04
  • x-ms-blob-type: BlockBlob
  • Content-Length:
  • Authorization: SharedKey : (or other auth methods)

Body: Blob data

Get Blob (Download)

Request: GET https://.blob.core.windows.net//

Headers:

  • x-ms-version: 2020-08-04
  • Authorization: SharedKey :

Response Body: Blob data

💡

Best Practices & Tips