c# - aspnet core - 浏览器未在文件结果中显示下载进度
问题描述
我有一个简单的网络应用程序,它允许下载文件。
该文件被正确下载,但是浏览器从不指示接收到的数据量(即进度)。
下载动作的实现如下 - 现在,只需打开读取本地文件并将流作为文件结果返回。
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 从不显示下载进度吗?
解决方案
您的代码应该可以解决问题。您应该尝试使用更大的文件(例如:200mb)吗?这可能是计算 ETA 所花费的时间比在本地开发环境中下载更多的原因。
推荐阅读
- sml - 我不知道如何使用 PolyML 打开和运行 sml 文件
- kde - KDE SVN2GIT“警告:存储库中的分支...在修订版中不存在...-您是否从错误的修订版恢复?” 无法继续
- node.js - 反应安装问题
- python - to_sql 将 DataFrame 插入 [schema].[table] 时出现“语法错误”错误
- react-native - 无法加载脚本确保您正在运行 Metro 服务器
- c++ - GMock 铸造到基地失去了模拟行为
- java - 解析 Json 数据。嵌套对象给出错误
- jstree - 在 jsTree 中显示自定义图像 - 从 HTM 代码构建树
- mysql - 无法更新存储函数/触发器中的表“table2”,因为它已被调用此存储函数/触发器的语句使用
- android - 扩展嵌套项 FastAdapter