I have a file browser application in MVC4 that allows you to download a selected file from a controller.
Currently, the FileResult returns the Stream of the file, along with the other response headers. While this works fine for smaller files, files that are larger generate an OutOfMemoryException.
What I'd like to do is transmit the file from the controller, without buffering in memory in a fashion similiar to HttpReponse.TransmitFile in WebForms.
How can this be accomplished?
You can disable the response buffer before you return the file result.
Response.BufferOutput = false;
return File(fileStream, contentType);
Yes you can by using Web Api in order to stream the file, take a look at this article Dealing with large files in ASP.NET Web API
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With