3

What I would like to do is stream the request to a file store asynchronously so that the incoming request does not take up a lot of memory and so that handling thread is not held up for IO.

I see that there is an asynchronous HTTP handler that I can implement. This looks like it would help with the thread usage, but it looks like the request has already been fully copied into memory by this point by IIS/ASPNET.

Is there a way to keep ASP.NET from reading the entire request in before handling it?

Randy Klingelheber
  • 947
  • 2
  • 9
  • 16
  • possible duplicate of [Streaming uploaded files directly into a database table](http://stackoverflow.com/questions/1743885/streaming-uploaded-files-directly-into-a-database-table) – Davide Piras Sep 21 '11 at 17:25
  • 1
    I should clarify that this is a web service currently implemented with a generic HTTP Handler. I am familiar with copying from one stream to another or to a database. What I'm not familiar with is how to keep the incoming HTTP request from being fully loaded into memory before I copy it elsewhere. – Randy Klingelheber Sep 21 '11 at 18:09
  • I notice you haven't responded to any of the answers here. Have you taken time to look at them and see if they do what you're looking for? – StriplingWarrior Sep 22 '11 at 21:14

3 Answers3

2

There is a new method added to the HttpRequest in .NET 4 called GetBufferlessInputStream(), which gives you synchronous access to the request stream.

From the MSDN article:

This method provides an alternative to using the InputStream property. The InputStream property waits until the whole request has been received before it returns a Stream object. In contrast, the GetBufferlessInputStream method returns the Stream object immediately. You can use the method to begin processing the entity body before the complete contents of the body have been received.

The ability to access the request stream asynchronously will be available in .NET 4.5. See the What's New in ASP.NET 4.5 article for more information. It looks like there will be several nice ASP.NET performance improvements in 4.5.

Randy Klingelheber
  • 947
  • 2
  • 9
  • 16
0

you are not searching SO enough.

the solution you need is explained here, step by step, in very much details: Efficiently Uploading Large Files via Streaming

check this one, your question is a duplicated: Streaming uploaded files directly into a database table

Community
  • 1
  • 1
Davide Piras
  • 43,984
  • 10
  • 98
  • 147
0

While this SO question is specifically about MVC, the answers should work for ASP.NET generally. Specifically, people appear to have had a good experience with Darren Johnstone's UploadModule.

Community
  • 1
  • 1
StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315