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,050 points
135 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
73 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,140 points
783 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
1,962 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
337 views
0 votes
3 answers

What is the job role of a Azure Architect?

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

answered 1 day ago in Career Counselling by Abha
• 9,340 points
31 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 1 day ago in Career Counselling by Abha
• 9,340 points
157 views
0 votes
3 answers

What is the salary offered to a Azure Architect?

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

answered 1 day ago in Career Counselling by Abha
• 9,340 points
22 views
0 votes
3 answers

Can freshers apply for the job of Azure Architect?

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

answered 1 day ago in Career Counselling by Abha
• 9,340 points
29 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
100 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
19 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.