Sameer
Sameer

Reputation: 11

Can't download file larger than 2 gb in MVC

I want to download a zip file but its size is more than 2 gb. I am facing an problem due to the limitation of 2 gb size in byte[] array. How can I download the zip file?

FileContentResult fileContent = new 
FileContentResult(System.IO.File.ReadAllBytes(exportDirectoryZip), 
"application/zip")
{
    FileDownloadName = Path.GetFileName(exportDirectoryZip)
};



//FOR VIEWS
var cd = new System.Net.Mime.ContentDisposition
{
    Inline = true,
    FileName = fileContent.FileDownloadName
};

//Response.AddHeader("Content-Disposition", cd.ToString());

return File(fileContent.FileContents, "application/zip");

Upvotes: 1

Views: 810

Answers (1)

user585968
user585968

Reputation:

It's terribly inefficent to load a large file (particularly 2GB) into memory that is merely being streamed to a client, not to mention that you run into memory issues on a 32-bit process. You are much better off loading the file for streaming and returning the stream instead. This lowers the memory impact of the host.

Upvotes: 1

Related Questions