Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i upload file size 1.25GB in ASP.NET MVC

Tags:

c#

asp.net

My client is uploading file more then 1 GB through application. I know i can only upload only 100mb using asp.net MVC application.

 public static byte[] ReadStream(Stream st)
     {
         st.Position = 0;
         byte[] data = new byte[st.Length];
         .
         .
         .        
         . 
}

i am getting error at byte[] data = new byte[st.Length]; because st.Length=1330768612 Error - "Exception of type 'System.OutOfMemoryException' was thrown."

Is there any way i can upload more then 1gb file? Why we can define maxRequestLength= 0 - 2097151 in webconfig,

like image 992
Pankaj Avatar asked Jul 08 '10 07:07

Pankaj


People also ask

How can increase upload file size in ASP.NET MVC?

You need to add/update the values of "executionTimeout", "maxRequestLength" & "maxAllowedContentLength" properties if not already added in the "Web. config" file, as shown below. executionTimeout -> The amount of time required to process your request on the web server; The value is provided in seconds.

How do I handle a large file upload?

Possible solutions: 1) Configure maximum upload file size and memory limits for your server. 2) Upload large files in chunks. 3) Apply resumable file uploads. Chunking is the most commonly used method to avoid errors and increase speed.

What is the default size limitation of file upload in ASP.NET Fileupload control?

bydefault file upload limit set by asp.net is 20MB.


2 Answers

IMO you need to use the right tool for the job. Http was simply not intended to transfer large files like this. Why dont you use ftp instead, and maybe you could then build a web interface around that.

like image 139
Fen Avatar answered Sep 22 '22 17:09

Fen


The error shown to you suggests the server has not enough memory to process the file in memory. Validate if your server has enough memory to allocate such a big array/file.

You could also try to process chuncks of the stream. The fact that you get an out of memory suggests that the file is sent to the server, but the server cannot process the file.

I really think it has to do with the size of the array you allocate. It just won't fit in the memory of you machine (of in the memory assigned to .NET).

like image 39
Gertjan Avatar answered Sep 24 '22 17:09

Gertjan