Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Web API2 WebHostBufferPolicySelector UseBufferedInputStream override

$
0
0

Hello,

I would like to ask if it is necessary to override  UseBufferedInputStream  method in Custom WebHostBufferPolicySelector, where base on rout i can turon on/off buffering.

What i mean is that I am uploading large file through API and I want to use streaming, so I wont use that much of memory, I heard that by default WEB API is buffering request and i want to avoid it, so according to some materials What i have done is:

 public class NoBufferWebHostPolicySelector : 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(), "upload", StringComparison.InvariantCultureIgnoreCase))
                    return false;
            }

            return true;
        }
        //redundad
        public override bool UseBufferedOutputStream(HttpResponseMessage response)
        {
            return base.UseBufferedOutputStream(response);
        }
    }

-----
 protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            GlobalConfiguration.Configuration.Services.Replace(typeof(IHostBufferPolicySelector), new NoBufferWebHostPolicySelector());

        }

But then UseBufferedInputStream  method is called, context.Request.RequestContext.RouteData is always empty.

So now i am wondering if this is really thing I need to do, and if so, why I have context.Request.RequestContext.RouteData empty in this method.

Anyone can help me?


Viewing all articles
Browse latest Browse all 4850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>