I have a large zip file (500MB or greater) that I am reading into a MemoryStream and return as a FileStreamResult. However, I am getting a OutOfMemory Exception for files over 200MB. Within my Action I have the following code:
MemoryStream outputStream = new MemoryStream();
using (var fs = new FileStream(filepath, FileMode.Open, FileAccess.Read))
{
//Response.BufferOutput = false; // to prevent buffering
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0)
{
outputStream.Write(buffer, 0, bytesRead);
}
}
outputStream.Seek(0, SeekOrigin.Begin);
return new FileStreamResult(outputStream, content_type);