How to get public URL of Azure Files file?

devSparkle picture devSparkle · Dec 23, 2015 · Viewed 14.9k times · Source

I am using Azure Files to store files for my Web Application, which I have previously mentioned here.

I am currently processing the files/sub-directories within a directory, and outputting a navigation table so the user can navigate into sub-directories, and in the end, obtain said files. I'm doing this by using the methods described in the 'Access the file share programmatically' section of this Azure Documentation article.

My question is very simple, how can I, from my Web App, which is running in Azure app service, provide a public URL were the user can download/view the file?

Please note, I would prefer that the file is not automatically downloaded, since most of the files would be a .PDF, and therefor preview-able in the browser.

Answer

Gaurav Mantri picture Gaurav Mantri · Dec 23, 2015

My question is very simple, how can I, from my Web App, which is running in Azure app service, provide a public URL were the user can download/view the file?

One possible solution would be to create a Shared Access Signature (SAS) on the files with at least Read permission and use that SAS URL. Depending on the file's content type, the file's contents will be either displayed inline in the browser or the user will be prompted to download the file. If you want to force the download, you could always override Content-Disposition response header in the SAS.