Azure Blob Storage

Azure Blob Storage is Microsoft's object storage solution for the cloud. It is optimized for storing massive amounts of unstructured data, such as text or binary data. Blob storage can be used to serve images or documents directly to a browser, store files for distributed access, stream video and audio, write to log files, and back up data.

Key Features:
  • Scalable and cost-effective object storage.
  • Multiple access tiers (Hot, Cool, Archive) for cost optimization.
  • High availability and durability.
  • Supports REST API and SDKs for various programming languages.

Core Concepts

Storage Accounts

A storage account provides a unique namespace in Azure for your data. Every object you upload to Blob Storage is reference through your storage account. There are different types of storage accounts, but for Blob Storage, you'll primarily use General-purpose v2 (GPv2) or Blob storage accounts.

Blobs

Blobs are the fundamental building blocks of Blob Storage. There are three types of blobs:

Containers

A container is a logical grouping of blobs. It's similar to a folder in a file system, but with additional metadata and access control policies. You must create a container before you can upload blobs to it.

Access Tiers

Blob Storage offers different access tiers to store data cost-effectively. Choosing the right tier depends on how frequently you access your data.

Getting Started

Create a Storage Account

You can create an Azure Storage account using the Azure portal, Azure CLI, PowerShell, or SDKs. Here's a basic example using Azure CLI:


az storage account create \
    --name mystorageaccountname \
    --resource-group myresourcegroup \
    --location eastus \
    --sku Standard_LRS \
    --kind StorageV2
            

Upload a Blob

To upload a blob, you'll need the name of your storage account and a container. You can use Azure Storage Explorer or programming SDKs. Here's a conceptual example using Python:


from azure.storage.blob import BlobServiceClient

connect_str = "YOUR_CONNECTION_STRING" # Get this from your storage account
blob_service_client = BlobServiceClient.from_connection_string(connect_str)

container_name = "mycontainer"
blob_name = "myblob.txt"
local_file_name = "local_file_to_upload.txt"

# Create a container if it doesn't exist
try:
    blob_service_client.create_container(container_name)
except Exception as e:
    print(f"Container might already exist: {e}")

# Upload the blob
blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name)

with open(local_file_name, "rb") as data:
    blob_client.upload_blob(data)

print(f"Blob '{blob_name}' uploaded to container '{container_name}'.")
            

Further Reading