Out of memory while uploading

May 30, 2011 at 9:00 PM


It seems the server takes an uploaded file (POST) entirely in memory. I just want to save the uploaded file to file.

Is there a way of limited the memory usage in such a case ?  Or, if not, can I block these kinds of large uploads ? It seems this is an easy way to crash the server ?




Jun 16, 2011 at 4:48 AM

I'll make a patch tomorrow that will allow you to limit uploads. I'll also switch to a FileStream instead of a MemoryStream for the body if it's larger than a certain size.

Jun 16, 2011 at 11:02 AM

Hi Jonas,

This would be great. I was also thinking of an event being called for each body packet read (unparsed) or to provide a limit on the amount of bytes being read. This is to avoid that the webserver could easily be DOS'ed with very large HTTP body uploads.

Probably most of the time the Content-Length header could be read, but if I'm not mistaken this is not always set and I don't see a way to decide on how much data or skipped from the body in the process.



Jun 30, 2011 at 7:01 PM

This has been fixed now. Use Server.MaxContentSize to specify max length.

The server will throw an http exception if the content is larger.

The server will switch to a FileStream for the content (Request.Body) if it's larger than 2 000 000 bytes.