1

I have an ASP.NET Core 1.2 application which sends a file to a user. I use a FileResult for this purpose. My code looks like:

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

I have tried using response buffering as in https://github.com/aspnet/BasicMiddleware/blob/dev/samples/ResponseBufferingSample/Startup.cs#L17, but it did not work for me.

This returns the file correctly, but uses Transfer-Encoding: Chunked, which causes downloads to appear in "indeterminate" form i.e. without a progress bar. I have tried setting the Content-Length header myself, but it is removed automatically.

EDIT: Please note that as mentioned above, I have already tried response buffering. This did not solve my issue.

EDIT 2: The following is an SSCCE of the code I use

FilesController.cs > Action

[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 > Configure

app.UseStaticFiles();
app.UseResponseBuffering();
app.UseMvc();
Hele
  • 1,558
  • 4
  • 23
  • 39
  • 1
    Possible duplicate of [Disable chunking in Asp.Net Core](http://stackoverflow.com/questions/37966039/disable-chunking-in-asp-net-core) – Joel Harkes Feb 21 '17 at 07:45
  • 2
    You did not read my question. I have mentioned that I have tried response buffering and that did not work. I have even linked to the very same example saying it did not work. – Hele Feb 21 '17 at 14:29
  • nowhere does your code shows though that you tried to Disable chunking by setting this config. your code example is very minimalistic and so it is very hard to help you. Please then give us a minimal viable reproduce-able example. – Joel Harkes Feb 21 '17 at 15:10
  • @JoelHarkes I have added more code in my question. Let me know if you are still having any difficulties in reproducing the issue. – Hele Feb 21 '17 at 18:55

1 Answers1

0

This seems to have been a bug in the BrowserLink middleware. It was patched by MS a while back. Read the full thread at https://github.com/aspnet/Mvc/issues/5999 .

Hele
  • 1,558
  • 4
  • 23
  • 39