如何获取存储在Azure存储帐户中的数字文件的下载URL [英] How to get download url of a digital file stored in an Azure storage account
问题描述
在 Azure Blob存储
中存储了数字文件
之后,我想在我的静态网站中提供指向该文件的
link
(没有 no
服务器端代码).当用户单击该链接时,用户应该能够将该数字文件下载到他/她的计算机上.问题:如何获取存储在Azure blob存储中的数字文件的 url
?
After storing a digital file
in Azure blob storage
, I want to provide a link
to that file in my static website
(that has no
server side code). When a user clicks on that link user should be able to download that digital file to his/her computer. Question: How do you get the url
of a digital file stored in Azure blob storage?
推荐答案
Azure存储中的每个Blob都具有以下格式的URL:
Each blob in Azure Storage has a URL of the following format:
https://account.blob.core.windows.net/container/blob
位置:
account
是您的存储帐户的名称, container
是您的blob容器的名称,
blob`是您的blob的名称
account
is the name of your storage account, container
is the name of your blob containerand
blob` is the name of your blob.
现在,您的要求是,应提示用户直接下载文件而不使用任何服务器端代码,这是您需要做的其他事情:
Now that your requirement is that a user should be prompted to download the file directly without using any server-side code, these are the additional things you would need to do:
- 确保将blob容器的ACL设置为
Blob
(推荐)或Public
.如果将ACL设置为Private
,则需要一个Shared Access Signature(SAS)
,并且这将需要一些服务器端代码. - 将Blob的
content-type
设置为application/octet-stream
(Azure存储中任何Blob的默认内容类型)或设置content-disposition
属性附加到attachment;filename =您的文件名"
强制文件下载,而不是仅在浏览器中显示.推荐的方法是使用content-disposition
属性.
- Make sure that the blob container's ACL is either set to
Blob
(recommended) orPublic
. If you set the ACL toPrivate
, then you would need aShared Access Signature (SAS)
and that would require some server-side code. - Either set the
content-type
of the blob toapplication/octet-stream
(default content type for any blob in Azure Storage) or set thecontent-disposition
property toattachment; filename="your file name"
to force the file download instead of displaying it inside the browser only. Recommended approach is to usecontent-disposition
property.
这篇关于如何获取存储在Azure存储帐户中的数字文件的下载URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!