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 26, 2019 in Azure by sabby
• 4,370 points
7,233 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 26, 2019 by Prerna
• 1,960 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
1,605 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
• 58,020 points
14,013 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
24,735 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
21,889 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, 2019 in Career Counselling by Abha
• 28,140 points
1,387 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, 2019 in Career Counselling by Abha
• 28,140 points
11,207 views
+1 vote
3 answers

What is the salary offered to a Azure Architect?

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

answered Jun 18, 2019 in Career Counselling by Abha
• 28,140 points
3,403 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, 2019 in Career Counselling by Abha
• 28,140 points
1,317 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, 2019 in Azure by Prerna
• 1,960 points
12,626 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, 2019 in Azure by Prerna
• 1,960 points
1,372 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP