【发布时间】:2020-01-04 13:15:30
【问题描述】:
我有一个简单的网络应用程序,它允许下载文件。
该文件已正确下载,但浏览器从不指示接收到的数据量(即进度)。
下载动作的实现如下 - 现在,只需打开读取本地文件并将流作为文件结果返回。
public async Task<IActionResult> Download(string id)
{
var project = await this.service.GetById(id).ConfigureAwait(false);
if (project == null)
{
return this.NotFound($"Project [{id}] does not exist");
}
var file = new FileInfo(project.DownloadLocation);
this.Response.ContentLength = file.Length;
return this.File(file.OpenRead(), "application/octet-stream", file.Name);
}
下载由一个简单的动作链接触发:
<dd class="project-path">@Html.ActionLink("Here", "Download", "Download", new { id = Model.Id})</dd>
知道为什么 Chrome/Firefox 从不显示下载进度吗?
【问题讨论】:
标签: c# asp.net-core model-view-controller webapi