Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get public URL of Azure Files file?

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.

like image 358
devSparkle Avatar asked Dec 24 '22 11:12

devSparkle


2 Answers

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.

like image 100
Gaurav Mantri Avatar answered Jan 12 '23 01:01

Gaurav Mantri


Using Shared Access Signature (SAS) could be a solution but it is probably an overkill in the given scenario.

In provided scenario the Blob Storage with public access is the most practical way to store files. From documentation:

... You can specify that a container and its blobs, or a specific blob, are available for public access. When you indicate that a container or blob is public, anyone can read it anonymously; no authentication is required. Public containers and blobs are useful for exposing resources such as media and documents that are hosted on websites. To decrease network latency for a global audience, you can cache blob data used by websites with the Azure CDN.

https://azure.microsoft.com/en-us/documentation/articles/storage-introduction/

To set container permissions from the Azure Portal, follow these steps:

  1. Navigate to the dashboard for your storage account.
  2. Select the container name from the list. Clicking the name exposes the blobs in the chosen container
  3. Select Access policy from the toolbar.
  4. In the Access type field, select "Blob"
like image 38
VeganHunter Avatar answered Jan 12 '23 00:01

VeganHunter