Manage Blobs in Azure Blob Storage

This document covers essential operations for managing blobs within Azure Blob Storage, including uploading, downloading, deleting, and updating blob metadata and properties.

Key Concepts

Before diving into management operations, ensure you understand the following:

  • Blob Types: Understand the difference between Block Blobs, Append Blobs, and Page Blobs. This guide primarily focuses on Block Blobs.
  • Storage Account Hierarchy: Blobs reside within containers, which are part of a storage account.
  • Access Control: Permissions for accessing blobs are managed at the container or blob level.

Uploading Blobs

Uploading blobs is a fundamental operation. You can upload blobs of various sizes using different methods.

Uploading a Block Blob

For general-purpose storage, block blobs are the most common choice. Here's a conceptual example using Azure CLI:

az storage blob upload \
    --account-name mystorageaccount \
    --container-name mycontainer \
    --name myblob.txt \
    --file /path/to/local/myblob.txt \
    --auth-mode login

Using SDKs

Azure provides SDKs for various programming languages to interact with Blob Storage. Refer to the specific SDK documentation for detailed examples.

Downloading Blobs

Downloading blobs allows you to retrieve data from Azure Blob Storage.

Downloading a Blob to a File

Example using Azure CLI:

az storage blob download \
    --account-name mystorageaccount \
    --container-name mycontainer \
    --name myblob.txt \
    --file /path/to/local/downloaded_myblob.txt \
    --auth-mode login

Managing Blob Properties and Metadata

Blobs have system properties (like content type, content length) and user-defined metadata that you can manage.

Setting Blob Metadata

Metadata is stored as key-value pairs and is accessible via HTTP headers. It can be set during upload or updated later.

az storage blob metadata update \
    --account-name mystorageaccount \
    --container-name mycontainer \
    --name myblob.txt \
    --metadata 'key1=value1,key2=value2' \
    --auth-mode login

Getting Blob Properties

You can retrieve properties and metadata of a blob:

az storage blob show \
    --account-name mystorageaccount \
    --container-name mycontainer \
    --name myblob.txt \
    --auth-mode login

Deleting Blobs

Blobs can be deleted individually or in bulk. Be cautious when deleting data.

Deleting a Single Blob

Example using Azure CLI:

az storage blob delete \
    --account-name mystorageaccount \
    --container-name mycontainer \
    --name myblob.txt \
    --auth-mode login

Blob Operations and Best Practices

Important: Deleting a blob is a permanent operation. Ensure you have backups or are certain before proceeding with deletion. Soft delete for blobs can help protect against accidental deletion.