Streaming File Downloads from Azure Blob Storage through ASP.NET Core

Often times when working with Azure Blob Storage you don’t want to expose access to the service directly but rather have requests go through your own API. This allows you to control access and hide the underlying service. However, you need to be careful to not put unnecessary extra load on your service during file operations by buffering up- or downloads in memory. You may not notice this at first for smaller files like images, but I can severely impact your service performance when larger files are in play.

Here’s how you can pass a file stream from Azure Blob Storage directly to an ASP.NET Core controller response:

[HttpGet("download/{container}/{blobName}")]
public async Task<IActionResult> DownloadFile([FromRoute] string container, [FromRoute] string blobName)
{
Uri containerUri = new($"{BlobStorageEndpoint}/{container}");
BlobContainerClient containerClient =
new(containerUri, new DefaultAzureCredential());
BlobClient blobClient = containerClient.GetBlobClient(blobName);
// Open a read stream directly from Azure Blob Storage
Stream blobStream = await blobClient.OpenReadAsync();
// Optionally, get blob properties for content type
Azure.Response<BlobProperties> properties =
await blobClient.GetPropertiesAsync();
string contentType = properties.Value.ContentType
?? "application/octet-stream";
// Return FileStreamResult (without buffering entire file)
return File(blobStream, contentType, blobName);
}

Originally published at https://medienstudio.net on October 23, 2025.

Learn more Streaming File Downloads from Azure Blob Storage through ASP.NET Core

Leave a Reply