By default, the mode of receiving request data at a Web API service is in Buffered mode. This is good for most scenarios, but it could be a performance problem when you expect users to upload huge files to the service. In this scenario the files would be first buffered and then you would start working on it. Since this is not ideal, in this short post I show how to enable Streamed mode of receiving data at the Web API service.
Currently the approach for enabling buffered/streamed mode of receiving data is different between SelfHost and WebHost scenarios and also the capabilities are also different.
There is a service called IHostBufferPolicySelector on HttpConfiguration, which as the name indicates is for the purpose of tuning your requests to be enable buffered/streamed mode. Currently there is only one implementation of it called WebHostBufferPolicySelector which as its name indicates is only for Web Host scenarios.
Register this service in HttpConfiguration.
No implementation of IHostBufferPolicySelector currently. However, one could enable Streamed mode in Self Host by doing the following:
You can visit this documentation for more details about the TransferMode.
As you can see currently you have the ability of enabling streamed/buffered mode on a per-request basis in Web Host, where as in Self Host scenarios, you would need to enable it for the whole service.