Javascript下载一个URL - Azure Blob存储 [英] Javascript download a URL - Azure Blob Storage

查看:176
本文介绍了Javascript下载一个URL - Azure Blob存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Azure Blob存储,我希望用户能够下载文件。当用户点击要下载的文件时,我使用AJAX生成共享访问签名并返回要下载的URL。有没有办法让我,然后使用Javascript,下载文件?或者还有其他方法我可以使用...我也希望它不运行服务器端,因为没有理由不必要的费用,当我应该能够直接从URL下载...

I am using Azure Blob Storage, and I want users to be able to download files. When a user clicks a file they want to download, I use AJAX to generate a shared access signature and return the URL to download from. Is there any way for me to then, using Javascript, download the file? Or is there some other method I can use... I also would like it to not run server side, as there is no reason to incur unnecessary cost when I should be able to download directly from the URL...

基本上,Dropbox如何做...它是否以某种方式提交某种形式?

Basically, how Dropbox does it... Is it submitting some form somehow? It doesn't even have to be like that.

推荐答案

如果我理解正确,您希望用户看到打开/另存为提示当他们点击SAS URL。

If I understand correctly, you want your users to see Open/Save As prompt when they click on the SAS URL.

假设我的理解是正确的,最近Windows Azure Storage已经宣布了一些增强功能。其中一个增强功能是为blob添加 Content-Disposition 属性,这将允许此打开/另存为提示符以显示用户何时点击blob的SAS链接。 Content-Disposition ,您有两个选项:

Assuming my understanding is correct, recently Windows Azure Storage had announced some enhancements. One of the enhancement there is addition of Content-Disposition property for the blob which would allow this Open/Save As prompt to show when a user clicks on the SAS link for the blob. With Content-Disposition, you have 2 options:


  1. 设置 Content-Disposition 作为blob属性:在这种情况下,每当用户点击SAS链接时,将提示他们保存文件。但是在这种情况下,他们将始终提示SAS链接,用户永远无法在浏览器中内联文档。您可能会发现此链接对此有用: http://msdn.microsoft。 com / en-us / library / windowsazure / ee691966.aspx

  2. 设置 Content-Disposition as SAS URL的一部分:在这种情况下,只有当用户点击包含 Content-Disposition 的SAS URL时才会提示用户。您可能会发现此链接对此有用: http://msdn.microsoft。 com / en-us / library / windowsazure / dn140255.aspx

  1. Set Content-Disposition as blob property: In this case, whenever user clicks on the SAS link, they will be prompted to save the file. But in this case, they will always be prompted so SAS link or not, user would never be able to see the document inline in the browser. You may find this link useful for this: http://msdn.microsoft.com/en-us/library/windowsazure/ee691966.aspx.
  2. Set Content-Disposition as part of SAS URL: In this case, a user will only be prompted when they click on the SAS URL which contains Content-Disposition. You may find this link useful for this: http://msdn.microsoft.com/en-us/library/windowsazure/dn140255.aspx.

所以假设你有一个png文件。在选项1中,它不会在浏览器中内联显示,它将被下载到客户端计算机上并在计算机上的注册图像查看器中打开。在选项2中,如果在SAS URL中设置了 Content-Disposition ,则图像文件将被下载到客户端计算机上,并在计算机上的注册图像查看器中打开,否则将直接显示在浏览器中。

So assuming you have a png file. In option 1, it will never be displayed inline in the browser, it will be downloaded on the client machine and opened in the registered image viewer on your computer. In option 2, if Content-Disposition is set in the SAS URL, the image file will be downloaded on the client machine and opened in the registered image viewer on your computer otherwise it will be displayed directly in the browser.

如果您使用的是.Net,Storage Client库3.0.0.0支持此功能,因此您不必编写包装REST API(但我认为您使用PHP ...从您之前关于CORS的问题))。

If you're using .Net, Storage Client library 3.0.0.0 has support for this feature so you don't have to write wrapper around the REST API (but I think you're using PHP ... from your previous question about CORS :)).

这篇关于Javascript下载一个URL - Azure Blob存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆