4

I have an ASP.NET MVC action that receives a file via HttpPostedFileBase.

I want to start reading from the stream as soon as possible. This is so I can report upload progress (via a separate mechanism). The issue that I have is that my break point inside this action is not hit until the uploaded file is available in it's entirety.

How can I being reading the posted file stream before it's fully uploaded?

[HttpPost]
public ActionResult Upload(HttpPostedFileBase uploadFile)
{
    ... uploadFile has been fully uploaded before this point
}

Edit: Update - I've now tried another way, implementing this logic via an HttpHandler, but still, the moment I begin to read from the stream, the code blocks until the file stream has completed upload to the server.

No luck as yet.

gbro3n
  • 6,729
  • 9
  • 59
  • 100
  • It sounds like what you're looking for is Chunk support. I don't have a full answer but that may give you something to go on. – Nick Albrecht Mar 06 '13 at 14:51
  • Have you looked at file upload controls like `http://fineuploader.com` as they do a great job and have the nice informative progress bars – Kane Mar 06 '13 at 14:57
  • I'd like to keep this as a SignalR based implementation as it is currently, as there's work to do after processing that I'll be reporting back to the client on. – gbro3n Mar 06 '13 at 15:02
  • http://stackoverflow.com/questions/692184/large-file-uploading-to-asp-net-mvc check this – Shoaib Shaikh Mar 06 '13 at 18:41

1 Answers1

1

The problem is that using several properties on the HttpContext.Request object cause ASP.NET to wait until the full post data has been processed. The key to circumventing this issue is HttpContext.Request.GetBufferlessInputStream(). This however requires processing, and there is no built in way to do this.

The solution in the end was to create classes that can parse the multipart content in the raw post data, which I achieved by looking at how its done in ASP.NETs HttpContext.Request code. I found various components in System.Web and was able to adapt to my needs.

The code now makes up part of the project I've written up here:

https://journals.appsoftware.com/public/20/97/3819/programming-blog/development/asp.net-file-uploader-with-signalr-progress-bar-and-extended-input-stream-processing

gbro3n
  • 6,729
  • 9
  • 59
  • 100