Multiple Async File Uploads with chunking to ASP.Net Web API Multiple Async File Uploads with chunking to ASP.Net Web API multithreading multithreading

Multiple Async File Uploads with chunking to ASP.Net Web API


I'm not familiar with that kind of chunked upload, but I believe this should work:

  • Use flowTotalSize to pre-allocate the file when the first chunk comes in.
  • Have one SemaphoreSlim per file to serialize the asynchronous writes for that file.
  • Each chunk will write to its own offset (flowChunkSize * (flowChunkNumber - 1)) within the file.

This doesn't handle situations where the uploads are unexpectedly terminated. That kind of solution usually involves allocating/writing a temporary file (with a special extension) and then moving/renaming that file once the last chunk arrives.

Don't forget to ensure that your file writing is actually asynchronous.


Using @Stephen Cleary's answer, and this thread: https://github.com/flowjs/ng-flow/issues/41 I was able to make an ASP.NET Web Api Implementation and uploaded it for those still wondering about this question such as @Herb Caudill

https://github.com/samhowes/NgFlowSample/tree/master.

The original answer is the real answer to this question, but I don't have enough reputation yet to comment. I did not use a SemaphoreSlim, but instead enabled file Write sharing. But did in fact pre-allocate and make sure that each chunk is getting written to the right location by calculating an offset.

I will be contributing this to the Flow samples at: https://github.com/flowjs/flow.js/tree/master/samples