Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9196755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:55:12+00:00 2026-06-17T21:55:12+00:00

I am writing an ASP.NET Web API application that requires me to accept a

  • 0

I am writing an ASP.NET Web API application that requires me to accept a file upload and forward that file on to another HTTP endpoint.

I am concerned that if many users try to upload a 100MB file each (which is a valid use case) then my application will have a large memory footprint and depending on the volume of large requests this footprint could grow to large and my application would keel over and die.

Ideally I’d like begin streaming the file to the other HTTP end point as soon as the web server starts to receive the file to significantly reduce the load on the server.

I’m sure this process has a name but I don’t know it – which is making searching for it rather tough.

I’ve done quite a bit of work with Response Streaming in the Web API but I’ve never had to consider request streaming before.

Best I can tell I need to work out how to:

  • Begin processing the stream before it has finished uploading.
  • Use the HttpClient to stream the same request to stream the same data to the other HTTP end point.

Can anyone offer me some pointers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:55:14+00:00Added an answer on June 17, 2026 at 9:55 pm

    That’s an interesting question. I’ll try to do my best to give some general pointers.

    Few things to consider:

    1) Web API by default buffers requests so your fear that the memory footprint might be considerable is definitely justified. You can force Web API to work with requests in a streamed mode:

        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 replace the service:

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

    Please note that due to differences between WebHost and SelfHost at this point, such change is only possible in WebHost. If your endpoint is selfHosted, you would have to set the streaming mode at the GlobalConfig level:

    //requests only
    selfHostConf.TransferMode = TransferMode.StreamedRequest;
    //responses only
    selfHostConf.TransferMode = TransferMode.StreamedResponse;
    //both
    selfHostConf.TransferMode = TransferMode.Streamed;
    

    I have blogged about dealing with large files in Web API in more details before – http://www.strathweb.com/2012/09/dealing-with-large-files-in-asp-net-web-api/ so hopefully you’ll find that useful.

    2) Secondly, if you use HttpClient, in .NET 4 it buffers the requests body by default, so you should really use .NEt 4.5.

    If you have to use .NET 4 you have to work with HttWebRequest directly:
    – http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.allowreadstreambuffering.aspx
    – http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.allowwritestreambuffering.aspx

    3) As far as pushing the data to the client that’s definitely possible if you want to do that, with PushStreamContent.
    Henrik has a short introductory post here – http://blogs.msdn.com/b/henrikn/archive/2012/04/23/using-cookies-with-asp-net-web-api.aspx (it’s based on Web API RC bits so you might need to adjust some signatures etc.)
    I also blogged about pushing chunks of stream data here – http://www.strathweb.com/2013/01/asynchronously-streaming-video-with-asp-net-web-api/

    EDIT: To see an example if PushStreamContent in the request, you can have a look at this sample solution – http://aspnet.codeplex.com/SourceControl/changeset/view/bb167f0b0013#Samples/Net45/CS/WebApi/UploadXDocumentSample/ReadMe.txt

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a web application on Asp.Net MVC 3. Assume that we have
I'm writing an ASP.Net Web Application that can be deployed to Web Farms. I've
I am writing an API for my ASP.NET application that other developers will use.
I'm writing an asp.net Web Application. I wrote a login page that authenticates a
I'm writing an ASP.NET web application that transmits JSON between the client and the
I am writing a C# asp.net web application that receives CV's in various formats
I'm writing a ASP.NET Web Application and I'm running into trouble getting the CSS
I am writing an ASP.Net MVC 3 Web Application using Entity Framework 4.1. My
In a asp.net/c# web application I am writing a jQuery script. I have an
I am working on a ASP.NET/C# web application. I am writing a Jquery script.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.