Friendly filename when downloading Azure blob.

0 votes

Is it possible to save a blob with a name of a GUID but when a user requests the files URI http://me.blob.core.windows.net/mycontainer/9BB34783-8F06-466D-AC20-37A03E504E3F the download comes down with a friendly name e.g. MyText.txt?

Mar 15 in Azure by sabby
• 4,350 points
40 views

1 answer to this question.

0 votes

Azure blobs can be downloaded in four ways:

  • Direct Download 

  • API Download 

  • Proxy Download

  • Pass-through Download (Azure Shared Access Signature) - Creates a signature and inserts this signature in a URL where the user is redirected to Azure. The signature enables the user to access the file for a limited period of time. This is most likely your best option. It enables custom code to be executed before downloading, it will ensure max download speed for your users, and a good level of security is also ensured.

Following code streams the file to the user and overrides the filename:
//Retrieve filenname from DB (based on fileid (Guid))
// *SNIP*
string filename = "some file name.txt"; 

//IE needs URL encoded filename. Important when there are spaces and other non-ansi chars in filename.
if (HttpContext.Current.Request.UserAgent != null &&     HttpContext.Current.Request.UserAgent.ToUpper().Contains("MSIE"))
filename = HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8).Replace("+", " ");

context.Response.Charset = "UTF-8";
//Important to set buffer to false. IIS will download entire blob before passing it on to user if this is not set to false
context.Response.Buffer = false;
context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
context.Response.AddHeader("Content-Length", "100122334"); //Set the length the file
context.Response.ContentType = "application/octet-stream";
context.Response.Flush();

//Use the Azure API to stream the blob to the user instantly.
// *SNIP*
fileBlob.DownloadToStream(context.Response.OutputStream);
answered Mar 15 by Prerna
• 1,940 points

Related Questions In Azure

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,623 views
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
112 views
+1 vote
1 answer

Can I rename a Azure Storage Blob?

Though the approach I'm about to share ...READ MORE

answered May 10, 2018 in Azure by club_seesharp
• 3,450 points
727 views
0 votes
2 answers

Reading PDF file from Azure blob storage

For pdf reading and manipulating Itextsharp libraby is fine. For ...READ MORE

answered Aug 17, 2018 in Azure by Priyaj
• 56,520 points
942 views
0 votes
1 answer

How to install Windows Azure Storage Emulator?

There may be an issue with the ...READ MORE

answered Mar 6 in Azure by Prerna
• 1,940 points
70 views
0 votes
1 answer

Azure Storage Emulator shows error.

This blog might help with your query: http://blog.smarx.com/posts/windows-azure-storage-emulator-the-process-cannot-access-the-file-because-it-is-being-used-by-another-process Also, ...READ MORE

answered Mar 15 in Azure by Prerna
• 1,940 points
70 views
0 votes
1 answer

How to debug Azure 500 internal server error?

You can simply turn off custom error in ...READ MORE

answered Mar 29 in Azure by Prerna
• 1,940 points
164 views
0 votes
1 answer

Trying to understand Load Balancing in Azure.

For your clarification - Azure DOES support load balancing in ...READ MORE

answered Mar 29 in Azure by Prerna
• 1,940 points
21 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
33 views
0 votes
1 answer

Chrome's default HTML5 player is not working when video is uploaded to Azure Storage.

I don't know much about Windows Storage, ...READ MORE

answered Apr 23 in Azure by Prerna
• 1,940 points
43 views