简体   繁体   English

在MVC中无法下载大于2 GB的文件

[英]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. 我想下载一个zip文件,但大小超过2 GB。 I am facing an problem due to the limitation of 2 gb size in byte[] array. 由于byte []数组中2 GB大小的限制,我遇到了一个问题。 How can I download the zip file? 如何下载zip文件?

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");

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. 将大文件(特别是2GB)加载到仅以流形式传输到客户端的内存中,效率很低,更不用说在32位进程中遇到内存问题。 You are much better off loading the file for streaming and returning the stream instead. 您最好加载要进行流传输的文件并返回流。 This lowers the memory impact of the host. 这样可以降低主机对内存的影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM