Basically, I want to transfer the file to the web API and once in the web-api controller, I would like to transfer the data when it comes to the lower level logic through the stream reader. I tried the code below, found from another SO post with some changes, but I get:
Asynchronous module or handler completed while asynchronous operation is not completed yet.
public async void Put(int id, HttpRequestMessage request) { if (!Request.Content.IsMimeMultipartContent()) throw new InvalidOperationException(); var provider = new MultipartMemoryStreamProvider(); await Request.Content.ReadAsMultipartAsync(provider); var file = provider.Contents.First(); var filename = file.Headers.ContentDisposition.FileName.Trim('\"'); var buffer = await file.ReadAsByteArrayAsync(); var stream = new MemoryStream(buffer); using (var s = new StreamReader(stream)) { saveFile.Execute(id, s); } }
I am open to other solutions as long as I transmit data as they become available. I am new to standby and asynchronous mode and I am probably making a basic mistake. Any ideas?
Joshua enfield
source share