Basically I want to stream a file to a web API and once inside the web api controller I would like to pass data as it comes in to lower level logic via a stream reader. I tried the code below found from another SO post with some modification, but I get:
An asynchronous module or handler completed while an asynchronous operation was still pending.
    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'm open to other solutions as long as I am streaming the data as it comes in. I'm new to await and async and I'm probably making a basic mistake. Any ideas?
Change async void to async Task
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With