wasAsked.

How did you store data in azure storage?

Wipro · Role not specified · technical

Published

Year not specified · Azure

Community answers

Posted by wasAsked editorial collection

Azure Storage offers several services; I would choose based on the data: - Blob Storage: files and unstructured data (documents, images, backups, exports). - Table Storage: simple, cheap key-value / NoSQL data (Cosmos DB for Table is the premium alternative). - Queue Storage: simple message queues between components. - Azure Files: SMB or NFS file shares for lift-and-shift applications. Example: storing uploaded documents in Blob Storage from ASP.NET Core 1. Authenticate with managed identity (no account keys) builder.Services.AddSingleton(_ => new BlobServiceClient( new Uri("https://mystorage.blob.core.windows.net"), new DefaultAzureCredential())); Assign the app's identity the Storage Blob Data Contributor role on the container or account. 2. Upload public async Task<string> UploadAsync(Stream content, string contentType, CancellationToken ct) { var container = _blobService.GetBlobContainerClient("documents"); var blobName = $"{DateTime.UtcNow:yyyy/MM}/{Guid.NewGuid()}"; // never trust user file names var blob = container.GetBlobClient(blobName); await blob.UploadAsync(content, new BlobUploadOptions { HttpHeaders = new BlobHttpHeaders { ContentType = contentType } }, ct); return blobName; // store this reference and metadata in the database } 3. Download securely - Stream through an authorized API endpoint, or issue a short-lived, read-only SAS URL (a user delegation SAS signed with Entra credentials is preferred over account-key SAS). Design practices - Keep containers private (no anonymous access); store metadata (owner, original file name, size) in your database. - For large files, let clients upload directly with a short-lived SAS URL and chunked uploads, instead of streaming through the API. - Access tiers and lifecycle management policies: move old data from Hot to Cool, Cold or Archive automatically to reduce cost. - Data protection: soft delete, versioning, point-in-time restore, and immutability policies for compliance data. - Redundancy: LRS, ZRS or GRS/GZRS depending on availability needs. - Networking: private endpoints and firewall rules for sensitive data; encryption at rest is automatic (customer-managed keys optional). - Event-driven processing: Event Grid "BlobCreated" events can trigger a Function to scan or resize uploaded files.

Ravindra Wadile · · 0 likes

Sign in to add your answer

Related interview topics