Azure Blob Storage Advanced
Master advanced Azure Blob Storage features for scalable data management.
A Simple Analogy
Azure Blob Storage is like a massive filing cabinet in the cloud. Store documents, images, videos, logs—any file. Organize them in containers, control access, and retrieve them globally at high speed.
What Is Blob Storage?
Azure Blob Storage is managed object storage for unstructured data: files, videos, images, backups, logs. It scales massively and costs pennies per GB.
Blob Tiers
| Tier | Access | Cost | Use Case | |------|--------|------|----------| | Hot | Frequent access | Higher | Active files | | Cool | Infrequent | Lower | Backup, archive | | Archive | Rare access | Lowest | Long-term archive |
.NET Advanced Operations
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
var client = new BlobContainerClient(
new Uri("https://myaccount.blob.core.windows.net/container"),
new DefaultAzureCredential());
// Upload with metadata
var blobClient = client.GetBlobClient("documents/report.pdf");
await blobClient.UploadAsync(stream, overwrite: true);
await blobClient.SetMetadataAsync(new Dictionary<string, string>
{
{ "Department", "Finance" },
{ "CreatedBy", "John Doe" }
});
// List blobs with filter
await foreach (var blobItem in client.GetBlobsAsync(
BlobTraits.Metadata,
BlobStates.None,
"documents/"))
{
var blob = client.GetBlobClient(blobItem.Name);
Console.WriteLine($"{blob.Name}: {blobItem.Metadata["Department"]}");
}
// Soft delete and restore
var deletedBlobs = await client.GetBlobsAsync(BlobStates.Deleted);
foreach (var deletedBlob in deletedBlobs)
{
await client.GetBlobClient(deletedBlob.Name).UndeleteAsync();
}
// Snapshot for backup
var snapshot = await blobClient.CreateSnapshotAsync();
Practical Example: Log Archive
public class LogArchiveService
{
private readonly BlobContainerClient _containerClient;
public async Task ArchiveOldLogsAsync()
{
// List logs older than 30 days
var cutoffDate = DateTime.UtcNow.AddDays(-30);
await foreach (var blob in _containerClient.GetBlobsAsync(BlobTraits.Metadata))
{
if (blob.Properties.CreatedOn < cutoffDate)
{
// Move to archive tier
await _containerClient.GetBlobClient(blob.Name)
.SetAccessTierAsync(AccessTier.Archive);
}
}
}
public async Task<Stream> DownloadLogAsync(string logName)
{
var blobClient = _containerClient.GetBlobClient(logName);
var download = await blobClient.DownloadAsync();
return download.Value.Content;
}
}
SAS URL Generation
// Generate temporary access URL
var sasUri = _containerClient.GenerateSasUri(
Azure.Storage.Sas.BlobContainerSasPermissions.Read,
DateTimeOffset.UtcNow.AddHours(1));
// Share URL without exposing account key
return sasUri.ToString();
Best Practices
- Use lifecycle policies: Auto-archive old data
- Enable soft delete: Recover accidentally deleted data
- Implement SAS tokens: Temporary, limited access
- Monitor costs: Track storage by tier
- Encrypt data: Use customer-managed keys
Related Concepts
- Lifecycle management policies
- Replication strategies
- Shared Access Signatures (SAS)
- Backup and disaster recovery
- Data Lake Storage (hierarchy)
Summary
Azure Blob Storage provides scalable, cost-effective storage with advanced features like tiering, snapshots, and soft delete. Use these features to optimize costs while maintaining data durability.