You do not need to implement this interface, I just listed it as a link - this code is already part of the web API source (under System.Web.Http/Hosting/IHostBufferPolicySelector.cs )
What you need to do is override the base class System.Web.Http.WebHost.WebHostBufferPolicySelector
It's enough:
public class NoBufferPolicySelector : WebHostBufferPolicySelector { public override bool UseBufferedInputStream(object hostContext) { var context = hostContext as HttpContextBase; if (context != null) { if (string.Equals(context.Request.RequestContext.RouteData.Values["controller"].ToString(), "uploading", StringComparison.InvariantCultureIgnoreCase)) return false; } return true; } public override bool UseBufferedOutputStream(HttpResponseMessage response) { return base.UseBufferedOutputStream(response); } }
and then register your new class in Global.asax or WebApiConfig.cs (whichever you prefer):
GlobalConfiguration.Configuration.Services.Replace(typeof(IHostBufferPolicySelector), new NoBufferPolicySelector());
Filip w
source share