如何获取 public URL 的 Azure Files 文件?

How to get public URL of Azure Files file?

我正在使用 Azure 文件存储我的 Web 应用程序的文件,我之前提到过

我目前正在处理目录中的 files/sub-directories,并输出导航 table 以便用户可以导航到子目录,最后获取所述文件。我正在使用 this Azure Documentation article.

的 'Access the file share programmatically' 部分中描述的方法来执行此操作

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?

请注意,我希望文件 不是 自动下载,因为大多数文件都是 .PDF,因此可以在浏览器。

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?

一种可能的解决方案是在至少具有 Read 权限的文件上创建 Shared Access Signature (SAS) 并使用该 SAS URL。根据文件的内容类型,文件的内容将直接显示在浏览器中,或者提示用户下载文件。如果您想强制下载,您可以随时覆盖 SAS 中的 Content-Disposition 响应 header。

使用共享访问签名 (SAS) 可能是一种解决方案,但在给定的情况下可能有点矫枉过正。

在提供的场景中,具有 public 访问权限的 Blob 存储是最实用的文件存储方式。来自文档:

... 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/

要从 Azure 门户设置容器权限,请按照下列步骤操作:

  1. 导航到存储帐户的仪表板。
  2. Select 列表中的容器名称。单击名称会显示所选容器中的 blob
  3. Select 从工具栏访问策略。
  4. 在访问类型字段中,select "Blob"