在下载MVC3 Azure的BLOB文件 [英] Downloading Azure Blob files in MVC3

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

问题描述

我们的ASP.NET MVC 3应用程序在Azure上运行并使用斑点作为文件存储。我已经上传部分想通了。

Our ASP.NET MVC 3 application is running on Azure and using Blob as file storage. I have the upload part figured out.

视图都将有文件名,其中,点击时会提示文件下载屏幕出现。

The View is going to have the File Name, which, when clicked will prompt the file download screen to appear.

谁能告诉我如何去这样做?

Can anyone tell me how to go about doing this?

推荐答案

两个选项真的......首先是干脆直接将用户重定向到BLOB(如果斑点是在一个公共容器)。这看起来有点像:

Two options really... the first is to just redirect the user to the blob directly (if the blobs are in a public container). That would look a bit like:

return Redirect(container.GetBlobReference(name).Uri.AbsoluteUri);

如果团块是一个私营集装箱,您既可以使用一个共享访问签名并做redirection(重定向)像previous例如,或者你可以在你的控制器动作读取BLOB,并将它推到客户端作为下载:

If the blob is in a private container, you could either use a Shared Access Signature and do redirection like the previous example, or you could read the blob in your controller action and push it down to the client as a download:

Response.AddHeader("Content-Disposition", "attachment; filename=" + name); // force download
container.GetBlobReference(name).DownloadToStream(Response.OutputStream);
return new EmptyResult();

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

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