【发布时间】:2013-09-13 01:44:07
【问题描述】:
我们使用 ASP.NET MVC 4(演示)、WCF(逻辑)、Azure Blob 存储(存储)。
是否可以在不冻结网站导航的情况下实现流式下载(通过)?
我们确实需要“通过”,因为需要自定义标头(Content-Disposition 等)。这意味着 FilePathResult 和直接链接到 Azure 是不可能的。
现在下载是这样实现的:
[HttpGet]
public ActionResult DownloadTemplate(Guid templateId)
{
Response.Clear(); Response.BufferOutput = false;
DownloadResult result = Client.DownloadTemplate(templateId)
Response.AddHeader("Content-Type", MimeHelper.GetMimeType(result.FileName));
Response.AddHeader("Content-Disposition", "attachment; filename=" + result.FileName);
byte[] buffer = new byte[4096]; int readed = 0;
while ((readed = result.ContentStream.Read(buffer, 0, buffer.Length)) > 0)
{
if (Response.IsClientConnected)
{
Response.OutputStream.Write(buffer, 0, readed);
Response.Flush();
}
}
return new EmptyResult();
}
【问题讨论】:
-
据我所知,FileResult 的所有后代都在缓冲输出并等待操作完成,似乎需要 IHttpHandler 或类似的东西,但我不明白 IHttpHandler 只能服务一个请求
标签: c# wcf asp.net-mvc-4 azure-blob-storage