WebHostBufferPolicySelector only indicates whether the underlying request is paperless. This is what the Web API will do under the hood:
IHostBufferPolicySelector policySelector = _bufferPolicySelector.Value; bool isInputBuffered = policySelector == null ? true : policySelector.UseBufferedInputStream(httpContextBase); Stream inputStream = isInputBuffered ? requestBase.InputStream : httpContextBase.ApplicationInstance.Request.GetBufferlessInputStream();
So, if your implementation returns false, then the query doesn't matter.
However, ReadAsMultipartAsync() loads everything into a MemoryStream - because if you do not specify a provider, MultipartMemoryStreamProvider is used by default.
To automatically save files to disk during processing of each part, use MultipartFormDataStreamProvider (if you are dealing with files and form data) or MultipartFileStreamProvider (if you are dealing only with files).
Below is an example of asp.net or here . In these examples, everything happens in the controllers, but there is no reason why you would not use it, i.e. Formatter
Another option, if you really want to play with streams, is to implement a custom class that inherits from MultipartStreamProvider , which will start whatever processing you want as soon as it captures part of the stream. The use will be similar to the above providers - you need to pass it to the ReadAsMultipartAsync(provider) method.
Finally - if you feel suicidal - since the main stream of requests is theoretically without buffering, you can use something like this in your controller or formatter:
Stream stream = HttpContext.Current.Request.GetBufferlessInputStream(); byte[] b = new byte[32*1024]; while ((n = stream.Read(b, 0, b.Length)) > 0) {
But of course, this is very, due to the lack of a better word, "ghetto".