友情文件名时公开下载Azure的BLOB [英] Friendly filename when public download Azure blob

查看:137
本文介绍了友情文件名时公开下载Azure的BLOB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能挽救一个blob具有GUID的名称(或其他任何东西),但是当用户请求的URI文件的http://me.blob.core.windows.net/mycontainer/9BB34783-8F06-466D-AC20-37A03E504E3F下载下来有一个友好的名字,例如: MyText.txt?

Is it possible to save a blob with a name of a GUID (or anything else) but when a user requests the files URI http://me.blob.core.windows.net/mycontainer/9BB34783-8F06-466D-AC20-37A03E504E3F the download comes down with a friendly name e.g. MyText.txt?

推荐答案

使用户能够在Windows Azure中下载文件(斑点),可在4种方式进行;

Enabling users to download files (blobs) in Windows Azure can be done in 4 ways;


  • 直接下载 - 将集装箱公共读访问或全部公共读取权限访问和揭露网址给最终用户。这种方法的缺点是明显的安全性 - 你没有当URL被暴露控制访问的方式。也没有检测下载的方式,以及执行code前/后下载。

  • Direct Download – Set the Access of the Container to Public Read Access or Full Public Read Access and expose the URL to the end user. The drawback of this method is obviously security – you have no way of controlling access when the URL is exposed. There is also no way of detecting downloads, and to execute code before/after the download.

API下载 - 用户必须运行Windows应用程序,Silverlight的等。另外 - 应用程序必须包含storeaccount名称和关键 - 这可能危及安全。特别是如果你有使用同一个帐户(他们仍然可以拥有自己当然容器)几个客户。

API Download – The user must run a Windows App, Silverlight etc. Also – the app must contain the storeaccount name and key – which might compromise security. Especially if you have several customers using the same account (they can still have their own containers of course).

代理下载 - 让用户访问您的服务器上的URL - 然后从Azure中检索文件,并将其发送给用户。这样做的好处是,你必须下载的完全控制,可以前/下载后执行code和你没有揭露任何的Azure的URL /帐户信息。事实上 - 最终用户甚至不会看到该文件存储在Azure上。 您还可以覆盖的文件名这样。不利的一面是,所有流量通过你的服务器 - 这样你'会在这里得到一个瓶颈。

Proxy Download – Have the user access a URL on YOUR server – which then retrieves the file from Azure and sends it to the user. The advantage of this is that you have full control of downloads, you can execute code before/after downloading and you don’t have to expose any Azure URL’s / account info. In fact – the end user will not even see that the file is stored in Azure. You can also override the filename this way. A downside is that all traffic passes through your server – so you' might get a bottleneck here.

直通下载(Azure的共享访问签名) - 创建一个签名,并在用户被重定向到Azure中的URL中插入该签名。签名使用户能够访问该文件的时间有限的时间。这很可能是你最好的选择。它可以用来执行定制code下载前,将确保最大下载速度为您的用户和安全性的一个很好的水平也得到保证。

Pass-through Download (Azure Shared Access Signature) - Creates a signature and inserts this signature in a URL where the user is redirected to Azure. The signature enables the user to access the file for a limited period of time. This is most likely your best option. It enables custom code to be executed before downloading, it will ensure max download speed for your users, and a good level of security is also ensured.

下面是一个code段流哪个文件到用户,并覆盖文件名。

Here's a code snippet which streams files to user, and overrides the filename.

//Retrieve filenname from DB (based on fileid (Guid))
// *SNIP*
string filename = "some file name.txt"; 

//IE needs URL encoded filename. Important when there are spaces and other non-ansi chars in filename.
if (HttpContext.Current.Request.UserAgent != null &&     HttpContext.Current.Request.UserAgent.ToUpper().Contains("MSIE"))
filename = HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8).Replace("+", " ");

context.Response.Charset = "UTF-8";
//Important to set buffer to false. IIS will download entire blob before passing it on to user if this is not set to false
context.Response.Buffer = false;
context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
context.Response.AddHeader("Content-Length", "100122334"); //Set the length the file
context.Response.ContentType = "application/octet-stream";
context.Response.Flush();

//Use the Azure API to stream the blob to the user instantly.
// *SNIP*
fileBlob.DownloadToStream(context.Response.OutputStream);

请参阅本博文更多:<一href=\"http://blog.degree.no/2012/04/downloading-blobs-from-windows-azure/\">http://blog.degree.no/2012/04/downloading-blobs-from-windows-azure/

这篇关于友情文件名时公开下载Azure的BLOB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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