1

我有一个向用户发送文件的 ASP.NET Core 1.2 应用程序。我FileResult为此目的使用 a 。我的代码如下所示:

return PhysicalFile(Path.GetFullPath(filePath), QMimeTypeMap.GetMimeType(Path.GetExtension(file.Name)));

我曾尝试使用https://github.com/aspnet/BasicMiddleware/blob/dev/samples/ResponseBufferingSample/Startup.cs#L17中的响应缓冲,但它对我不起作用。

这将正确返回文件,但使用Transfer-Encoding: Chunked,这会导致下载以“不确定”形式出现,即没有进度条。我试过Content-Length自己设置标题,但它会自动删除。

编辑:请注意,如上所述,我已经尝试过响应缓冲。这并没有解决我的问题。

编辑 2:以下是我使用的代码的 SSCCE

FilesController.cs > 动作

[HttpGet("files")]
public async Task<IActionResult> Download(string driveName, [Bind(Prefix = "id")] uint? fileId = null, [Bind(Prefix = "download")] int forceDownload = 0)
{
    // Send file info
    string filePath = "...";
    HttpContext.Response.Headers["Content-Length"] = new System.IO.FileInfo(filePath).Length.ToString();
    return PhysicalFile(Path.GetFullPath(filePath), QMimeTypeMap.GetMimeType(Path.GetExtension(filePath)));
}

Startup.cs > 配置

app.UseStaticFiles();
app.UseResponseBuffering();
app.UseMvc();
4

1 回答 1

0

这似乎是 BrowserLink 中间件中的一个错误。不久前,它被 MS 修补了。阅读https://github.com/aspnet/Mvc/issues/5999上的完整主题。

于 2019-03-27T14:00:14.593 回答