Reputation: 11
I'm getting an Out of Memory Exception when using Http.Post
of a large file. I'm getting this exception when I tried to write the filestream data to the memory stream.
Upvotes: 1
Views: 4343
Reputation: 9891
None of the above answers work for me, this one does the job:
These lines are the key:
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(yourUri);
wr.KeepAlive = false;
wr.Timeout = System.Threading.Timeout.Infinite;
wr.ProtocolVersion = HttpVersion.Version10;
And here:
wr.AllowWriteStreamBuffering = false;
Hope this can help someone out there.
Upvotes: 1
Reputation: 7594
Set HttpWebRequest.AllowWriteStreamBuffering=false. This will cause HWR to send the data immediately, instead of buffering it in memory.
Upvotes: 0
Reputation: 156469
Obviously putting 300mb of data into memory is causing the CLR to reach its maximum memory footprint. Have you considered writing the file to some other kind of stream to avoid having it all in memory at the same time? Perhaps you could write the file directly to disk, and then process the file in chunks afterward, rather than loading the whole thing into memory at the same time.
Upvotes: 2