'Web Controller HttpPost copy Request.Body missing data
My web controller shall receive a (large ~ 2 MB) byte stream with [HttpPost] as endpoint and move the data to next process step (storing).
Since there can be a lot of calls I like to copy the body data asynchronously
This is my code
[HttpPost]
public IActionResult PostContent()
{
MemoryStream ms = new MemoryStream();
{
Task t = source.CopyToAsync(ms);
t.ConfigureAwait(false);
t.ContinueWith((t1) =>
{
fileWriter.Save(ms);
});
}
return Ok();
}
This is fired by one or multple REST-clients multiple times a second.
But when the callback function gets invoked, the stream in ms is incomplete.
When using
Task t = source.CopyToAsync(ms);
t.Wait(); <---- sync it
fileWriter.Save(ms);
instead, it is working.
So isn't it possible have this POST called multiple times not until the previous body is read? And if not what is the use of this to read async or am I making a mistake in thinking?
(Sorry for not using syntactic sugar)
Thanks !
[Edit]
This is what I get when waiting. The data is completed (by ~1.8 MB)
This is what I get using callback. It is only ~266 KB
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


