Skip to main content

Azure Blob SDK & Azure Cloud Services

Overview

Microsoft Azure is a cloud computing platform providing compute, storage, networking, security, identity, AI, and DevOps tooling.

Azure Blob Storage is Microsoft's scalable object storage service designed for:

  • File storage
  • Media hosting
  • Backups
  • Logging
  • Data lakes
  • Static websites

Blob Storage Use Cases

Use CaseExample
File UploadsImages, PDFs, Videos
BackupsSystem snapshots
Static HostingFrontend websites
StreamingVideo delivery
LogsApplication logging
Data LakesBig data analytics

Azure Storage Architecture


Storage Services

ServicePurpose
Blob StorageObject/file storage
Queue StorageMessaging
Table StorageNoSQL key-value
File SharesSMB file system

Blob Types

Blob TypeDescription
Block BlobFiles/images/videos
Append BlobLogging scenarios
Page BlobVirtual disks

Azure Blob Storage Hierarchy


Installing Azure Blob SDK

dotnet add package Azure.Storage.Blobs

Authentication Methods

MethodRecommended For
Connection StringDevelopment
Shared Access Signature (SAS)Temporary access
Managed IdentityProduction
Azure ADEnterprise auth
{
"AzureStorage": {
"ConnectionString": "DefaultEndpointsProtocol=https;..."
}
}

Blob SDK Workflow


Creating BlobServiceClient

using Azure.Storage.Blobs;

var client = new BlobServiceClient(connectionString);

Dependency Injection in ASP.NET Core

builder.Services.AddSingleton(x =>
{
return new BlobServiceClient(
builder.Configuration["AzureStorage:ConnectionString"]);
});

Common Operations

Creating Containers

var containerClient = client.GetBlobContainerClient("images");
await containerClient.CreateIfNotExistsAsync();

Uploading Files

var blobClient = containerClient.GetBlobClient("photo.jpg");
await blobClient.UploadAsync(stream);

Downloading Files

var response = await blobClient.DownloadAsync();
return response.Value.Content;

Deleting Files

await blobClient.DeleteIfExistsAsync();

Listing Blobs

await foreach (var blob in containerClient.GetBlobsAsync())
{
Console.WriteLine(blob.Name);
}

Upload Workflow


Generating SAS Tokens

Shared Access Signatures allow temporary secure access.

var sasUri = blobClient.GenerateSasUri(
BlobSasPermissions.Read,
DateTimeOffset.UtcNow.AddHours(1));

Blob Metadata & Tags

await blobClient.SetMetadataAsync(new Dictionary<string, string>
{
{ "UploadedBy", "Admin" }
});

await blobClient.SetTagsAsync(new Dictionary<string, string>
{
{ "Category", "Invoice" }
});

Blob Access Tiers

TierUsage
HotFrequently accessed
CoolInfrequent access
ArchiveRarely accessed
await blobClient.SetAccessTierAsync(AccessTier.Cool);

Security Best Practices

FeaturePurpose
Managed IdentityRemove secrets
SAS TokensLimited access
Private EndpointsInternal networking
EncryptionProtect data
RBACFine-grained permissions
using Azure.Identity;

var client = new BlobServiceClient(
new Uri("https://mystorage.blob.core.windows.net"),
new DefaultAzureCredential());

Azure RBAC Roles

RoleAccess
Storage Blob Data ReaderRead
Storage Blob Data ContributorRead/Write
OwnerFull access

Major Azure Cloud Services

ServicePurpose
App ServiceWeb app hosting
Azure FunctionsServerless
AKSKubernetes
Azure SQLManaged SQL
Cosmos DBNoSQL database
Service BusMessaging
Key VaultSecret management
Application InsightsMonitoring

Azure Cloud Architecture


Deploy ASP.NET Core to Azure

az webapp up --name myapp

Deploy workflow:


Azure Functions — Blob Trigger

public static class BlobTriggerFunction
{
[FunctionName("BlobTriggerFunction")]
public static void Run(
[BlobTrigger("images/{name}")]
Stream blob)
{
}
}

Azure Service Bus

FeatureDescription
QueuesPoint-to-point
TopicsPublish/subscribe
Dead Letter QueueFailed messages
Retry PoliciesReliability

Azure Key Vault

builder.Configuration.AddAzureKeyVault(
new Uri(vaultUrl),
new DefaultAzureCredential());

Application Insights

builder.Services.AddApplicationInsightsTelemetry();

Local Development with Azurite

docker run -p 10000:10000 mcr.microsoft.com/azure-storage/azurite

Dockerizing ASP.NET Core + Azure SDK

FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "MyApp.dll"]

Performance Optimization

OptimizationBenefit
Async UploadsScalability
CDNFaster delivery
CompressionLower bandwidth
Access TiersLower cost
Parallel UploadsFaster transfers

Retry Policies

var options = new BlobClientOptions
{
Retry =
{
MaxRetries = 5
}
};

Geo-Redundancy Options

ReplicationDescription
LRSLocal redundancy
ZRSZone redundancy
GRSGeo redundancy
RA-GRSRead-access geo redundancy

Lifecycle Management

Automatically move blobs to cheaper tiers:


Event-Driven Architecture


Common Pitfalls

MistakeProblem
Storing secrets in codeSecurity risk
Using account keys everywherePoor security
Missing retry policiesReliability issues
No lifecycle managementHigh storage cost
Large synchronous uploadsPoor scalability

Azure Blob SDK Cheat Sheet

TaskCode
Create Clientnew BlobServiceClient()
Get ContainerGetBlobContainerClient()
Upload BlobUploadAsync()
Download BlobDownloadAsync()
Delete BlobDeleteIfExistsAsync()
Generate SASGenerateSasUri()

Interview Questions

Beginner

  1. What is Azure Blob Storage?
  2. What is BlobServiceClient?
  3. Difference between containers and blobs?
  4. What are SAS tokens?
  5. What is Managed Identity?

Intermediate

  1. Explain Azure RBAC.
  2. Difference between Blob Storage tiers?
  3. How would you upload large files?
  4. Explain Azure Functions.
  5. What is Azurite?

Advanced

  1. How would you secure Azure Blob Storage?
  2. Explain Azure storage replication strategies.
  3. How would you design a scalable upload service?
  4. Explain event-driven architecture using Azure.
  5. How would you optimize Azure storage cost?

Learning Roadmap