0

I took the Web API template and made slight change to working endpoint for the download.

[HttpGet(Name = "GetWeatherForecast")]
public FileStream Get()
{
    var path = @"C:\Users\user1\download.msi";
    return new FileStream(path, FileMode.Open, FileAccess.Read);
}

It's a 100mb download and I'm getting Out of memory when I trying download the file.

Rod
  • 14,529
  • 31
  • 118
  • 230

1 Answers1

1

To output a file, you should use the File method:

var f = new FileStream(path, FileMode.Open, FileAccess.Read);
return File(f, "application/octet-stream");

If you return a FileStream, I guess ASP.NET will consider it as special type, attempting to serialize the entire object before outputing it.

shingo
  • 18,436
  • 5
  • 23
  • 42