Overview
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. Blobs can be accessed via HTTP/HTTPS and integrated with Azure services.
Getting Started
Follow these steps to create a storage account and a blob container.
# Install Azure CLI
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
# Log in
az login
# Create a resource group
az group create --name myResourceGroup --location eastus
# Create a storage account
az storage account create \
--name mystorageaccount \
--resource-group myResourceGroup \
--location eastus \
--sku Standard_LRS
# Create a container
az storage container create \
--account-name mystorageaccount \
--name mycontainer \
--public-access off
Authentication
Use Azure Active Directory (AAD) or Shared Access Signatures (SAS) for secure access.
Using Azure AD
var credential = new DefaultAzureCredential();
var blobServiceClient = new BlobServiceClient(new Uri("https://mystorageaccount.blob.core.windows.net"), credential);
Using SAS Token
sas=$(az storage container generate-sas \
--account-name mystorageaccount \
--name mycontainer \
--permissions rwl \
--expiry 2025-12-31T23:59:00Z \
-o tsv)
blobUrl="https://mystorageaccount.blob.core.windows.net/mycontainer?${sas}"
Uploading & Downloading Blobs
// Upload
var containerClient = blobServiceClient.GetBlobContainerClient("mycontainer");
var blobClient = containerClient.GetBlobClient("example.txt");
await blobClient.UploadAsync("localfile.txt", overwrite:true);
// Download
var downloadInfo = await blobClient.DownloadAsync();
using var downloadStream = File.OpenWrite("downloaded.txt");
await downloadInfo.Value.Content.CopyToAsync(downloadStream);
Code Samples
Explore more language SDKs:
Best Practices
- Enable soft delete for recovery.
- Use lifecycle management to transition data to cooler tiers.
- Encrypt data at rest with Microsoft-managed keys or customer-managed keys.
- Leverage Azure CDN for global content delivery.