Non-buffered file upload using Web API RRS feed

  • Question

  • User-271759024 posted

    In my brief usage of web api for file uploads following the guidance of excellent articles like this, it appears that the uploaded file is completely buffered into memory before post method in the ApiController is called. Is this accurate and, if so, is there a way to circumvent this?  I understand that web api is built by a series of HttpMessageHandlers which help abstract away the difficulties of web server development but in this case it would be nice regain controller over the post request stream so that it could be handled in a custom fashion.  

    Monday, July 16, 2012 9:13 PM

All replies

  • User-738028663 posted

    What you want exactly? And it's better to have it buffered before sending , it's more reliable instead of directly send it as stream.

    Monday, July 16, 2012 11:12 PM
  • User-257536521 posted

    Do you have a sample project that reproduces the issue? How are you determining that the file is buffered?

    Monday, July 16, 2012 11:37 PM
  • User-738028663 posted

    you said that so i assumed it's buffered. do one thing , tell me what you want to do , will implement and send it back , if possible. Fine?

    Tuesday, July 17, 2012 5:12 AM
  • User-271759024 posted

    To clarify, there are some very good example server-side implementations of handling single and multipart file uploads from a POST call such as this one.  What web api has done is given us a nicely abstracted way to handle incoming requests in, already deserialized into class objects like HttpRequestMessage.  To provide all of this abstaction the entire request message must be consumed and parsed before the HttpRequestMessage can be passed on to one of our methods in an implementatin of ApiController.  

    This makes sense and is extremely convenient, however in this case I am interested in dealing with the native incoming request stream on the server myself (when it is a file upload POST being received).  Instead of writing the uploaded file directly to disk I am interested in performing data processing on the file stream as it is being received.  The benefit here is that the file is not being buffered somewhere unnecessary.  If the data processing fails there is no need to continue the file upload from the client.  Also the upload progress that the user sees will include the progress of the data processing.  As the example I linked to stands now the file is completely uploaded (observed via wireshark and fiddler), providing a completed upload progress to the user, before the PostFile method is every called.  

    Friday, July 20, 2012 7:27 AM
  • User279010726 posted

    I know this is old, but did you ever find an answer?  I'm trying to cut down memory usage on the server (and client) and we have a lot of large file transfers via Web API POST.  I need a non-buffered upload just like you were seeking.

    Tuesday, July 11, 2017 7:19 PM