Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best way to download large files from azure cloud storage

I have an MVC web app running in azure that serves up large files like mp3's, pdf's, etc... that are stored in cloud storage. What's the best way to serve those files, so users can download them when clicking on a link/button?

The easy way is just to show them with:

<a href="...blob.core.windows.net/container/file.mp3">

But then the user has to right-click to download.

To force a download, you can return a File ActionResult:

public ActionResult GetPDF( string filename )
{
    return File( filename, "application/pdf", Server.HtmlEncode( filename ) );
}

The drawback with this ( I think ) is that the webrole has to read in the files and output them to the stream, which would consume resources, and potentially bog down the role with lots of users. Whereas the simple href link solution basically hands off the work so the browser talks directly to cloud storage.

Am I correct? Should I be concerned about the extra work on the webrole?

Is there another way to force a file download without burdening the webrole?

UPDATE:

So what I ended up doing was uploading the mp3's with Content-Type "binary/octet-stream" - this seems to force a download prompt. Not sure if it's a good practice, but it works so far.

like image 547
PeteShack Avatar asked May 13 '11 04:05

PeteShack


People also ask

Is AzCopy faster than storage explorer?

I would rate performance of the AzCopy better than Storage Explorer, it took ~3 mins less than storage explorer: AzCopy – 5 points. Storage Explorer – 3 points.

What is the maximum quota size for a file share in the Azure file service?

In local and zone redundant storage accounts, Azure file shares can span up to 100 TiB. However, in geo- and geo-zone redundant storage accounts, Azure file shares can span only up to 5 TiB.


2 Answers

Your assumption is correct, if you want to use the ActionResult you would need to download the file to the web role first and then stream it down to the client. If you can you want to avoid this particularly with large files and leave it up to Azure Storage because then Microsoft has to worry about dealing with the request, you don't have to pay for more web roles if you get lots of traffic.

This works well if all of the files you're hosting are public, but gets a little trickier if you want to secure the files (look into shared access signatures if that it what you want to do).

Have you tried setting the content type on the blob? Depending on how you've uploaded the files to blob storage they may not be set. If you're uploading the blobs through your own code you can access this through CloudBlob.Attributes.Properties.ContentType (from MSDN)

like image 70
knightpfhor Avatar answered Sep 21 '22 13:09

knightpfhor


You can return the outputFileName which contain the path where file is downloading and display that path at front end with message that file has been downloaded at location [...]

like image 24
Sadia Saqib Avatar answered Sep 25 '22 13:09

Sadia Saqib