0

I want to send large files >800 mb to cassansdra storage.But I am getting System.OutOfMemoryException .

Please find the code below:

HttpWebRequest request = WebRequest.Create(postUrl) as HttpWebRequest;

Stream requestStream = request.GetRequestStream();

byte[] buffer = new byte[8 * 1024];

int len;
while ((len = fileToUpload.File.Read(buffer, 0, buffer.Length)) >0)
{
    requestStream.Write(buffer, 0, len);
    requestStream.Flush();
}
return request.GetResponse() as HttpWebResponse;

Please suggest me which part of the code needs improvement?

fileToUpload is the exact stream of 800 MB from UI.

RB.
  • 36,301
  • 12
  • 91
  • 131
user1400915
  • 1,933
  • 6
  • 29
  • 55

1 Answers1

1

By default the maximum size of file uploaded using an HttpRequest is 4 MB (4096 KB). If you have access to code on the receiving end you can increase this in web.config although I have never tested it for 800+ MB files :) Keep in mind that Asp.Net will time-out any request after 180 seconds so that practically limits the size of file you can upload.

<httpRuntime
  executionTimeout="110" 
  maxRequestLength="4096" />

Uploading Files in ASP.NET 2.0

IMHO your best bet is to send the file in chunks using HttpModule. These might be of interest:

Large File Upload Using HttpHandler or HttpModule?

HttpHandler or HttpModule for file upload, large files, progress indicator?

Best of luck :)

Community
  • 1
  • 1
RollingCog
  • 294
  • 1
  • 5