How to download a file from Blob Storage to the browser?

0 votes

Here is how I am listing available files:

var azureConnectionString = CloudConfigurationManager.GetSetting("AzureBackupStorageConnectString");
var containerName = ConfigurationManager.AppSettings["FmAzureBackupStorageContainer"];
if (azureConnectionString == null || containerName == null)
    return null;

CloudStorageAccount backupStorageAccount = CloudStorageAccount.Parse(azureConnectionString);
var backupBlobClient = backupStorageAccount.CreateCloudBlobClient();
var container = backupBlobClient.GetContainerReference(containerName); 
var blobs = container.ListBlobs(useFlatBlobListing: true);
var downloads = blobs.Select(blob => blob.Uri.Segments.Last()).ToList();

I need to know how to pass that file down to the browser for a user to download without necessarily saving it to the server.

Mar 25 in Azure by sabby
• 4,350 points
194 views

1 answer to this question.

0 votes

If you use ASP.NET (core), you can stream the content to the browser without saving the file on the server and using FileStreamResult which is IActionResult would be more elegant solution.

var stream = await blob.OpenReadAsync();
return File(stream, blob.Properties.ContentType, option);

This is the best solution if you don't want to risk your SAS tokens getting stolen, they are just in the query string after all so are not encrypted even with https.

answered Mar 25 by Prerna
• 1,940 points

Related Questions In Azure

0 votes
1 answer

How to upload a file on to Azure Blob storage without writing a code?

You can find the below tools useful ...READ MORE

answered Apr 13, 2018 in Azure by club_seesharp
• 3,450 points
89 views
0 votes
2 answers

How can I download a .vhd image to my local machine from azure and upload the same to a different azure account?

From the Windows Azure Portal you can ...READ MORE

answered Aug 20, 2018 in Azure by Priyaj
• 56,160 points
1,160 views
0 votes
1 answer

Azure Blob: How to open a file in browser without downloading it?

First, because I was using a byte[] the controller ...READ MORE

answered Jun 20, 2018 in Azure by club_seesharp
• 3,450 points
2,300 views
0 votes
1 answer

How to get the list of names of Azure blob files in a container?

We can get some additional info like Size, ...READ MORE

answered Jun 27, 2018 in Azure by club_seesharp
• 3,450 points
538 views
0 votes
3 answers

What is the job role of a Azure Architect?

Hi Sradha, job role of a Azure ...READ MORE

answered Jun 18 in Career Counselling by Abha
• 17,400 points
38 views
0 votes
3 answers

What are the skills required for becoming an Azure Architect?

@Sradha, following skills are required for becoming ...READ MORE

answered Jun 18 in Career Counselling by Abha
• 17,400 points
232 views
0 votes
3 answers

What is the salary offered to a Azure Architect?

Hey Sradha, salary offered to a Azure ...READ MORE

answered Jun 18 in Career Counselling by Abha
• 17,400 points
31 views
0 votes
3 answers

Can freshers apply for the job of Azure Architect?

Hey Sradha, if you have great knowledge ...READ MORE

answered Jun 18 in Career Counselling by Abha
• 17,400 points
33 views
0 votes
1 answer

How to create a sub directory in a blob container?

There are two ways:  using the GetDirectoryReference looping through a containers ...READ MORE

answered Mar 26 in Azure by Prerna
• 1,940 points
235 views
0 votes
1 answer

Want to upload a blob file with huge size to azure in as little time as possible.

Microsoft Azure Storage Explorer is one of the ...READ MORE

answered Mar 27 in Azure by Prerna
• 1,940 points
27 views