Azure Documentation

Managing Blobs in Azure Blob Storage

This document provides a comprehensive guide to managing blobs in Azure Blob Storage. Blob storage is Microsoft's object storage solution for the cloud. It's optimized for storing massive amounts of unstructured data, such as text or binary data.

What are Blobs?

A blob is the most common type of Azure Storage object. Blob storage can be used to store:

Types of Blobs

Azure Blob Storage supports three types of blobs:

Creating and Uploading Blobs

Using the Azure Portal

  1. Navigate to your storage account in the Azure portal.
  2. Select the container where you want to upload the blob.
  3. Click the Upload button.
  4. Choose the file(s) you want to upload.
  5. Configure optional settings like blob type, access tier, and metadata.
  6. Click Upload.

Using Azure CLI


# Create a container (if it doesn't exist)
az storage container create --name mycontainer --account-name mystorageaccount --auth-mode login

# Upload a block blob
az storage blob upload --container-name mycontainer --file /path/to/your/local/file.txt --name blob.txt --account-name mystorageaccount --auth-mode login

# Upload an append blob
az storage blob upload --container-name mycontainer --file /path/to/your/log.txt --name log.append.txt --type append --account-name mystorageaccount --auth-mode login
            

Using Azure SDKs

Azure SDKs are available for various programming languages (Python, .NET, Java, Node.js, Go) to programmatically manage blobs. Refer to the official Azure SDK documentation for detailed examples.

Accessing and Downloading Blobs

Using the Azure Portal

  1. Navigate to your storage account and select the container.
  2. Click on the blob you want to access or download.
  3. For public blobs, you can directly access the URL.
  4. For private blobs, you can generate a shared access signature (SAS) or download the blob using the portal interface.

Using Azure CLI


# Download a blob
az storage blob download --container-name mycontainer --name blob.txt --file local_download.txt --account-name mystorageaccount --auth-mode login

# Get blob URL (for public blobs or with SAS)
az storage blob url --container-name mycontainer --name blob.txt --account-name mystorageaccount --auth-mode login
            

Blob Properties and Metadata

Each blob has properties that provide information about the blob, such as its name, size, ETag, and last modified time. You can also associate custom metadata with a blob.

Metadata Example (Azure CLI)


# Set metadata for a blob
az storage blob metadata update --container-name mycontainer --name blob.txt --metadata '{"customkey1":"customvalue1", "customkey2":"customvalue2"}' --account-name mystorageaccount --auth-mode login

# Get metadata for a blob
az storage blob show --container-name mycontainer --name blob.txt --account-name mystorageaccount --auth-mode login --query metadata
            

Blob Access Control

Blob access can be controlled using several mechanisms:

Security Best Practice: Whenever possible, avoid making blobs publicly accessible. Use Shared Access Signatures or RBAC for controlled access.

Blob Lifecycle Management

Azure Blob Storage offers lifecycle management policies that allow you to automatically transition blobs between access tiers or delete them based on age or other criteria. This helps optimize costs and manage data efficiently.

Common Lifecycle Management Rules:

Key Concepts

Understanding the different blob types and access tiers is crucial for optimizing storage costs and performance based on your application's needs.

For more advanced scenarios, including blob versioning, immutability policies, and change feed, please refer to the official Azure documentation.

Explore Blob Design Patterns Learn About Access Tiers