I can read a file from the form-data and save it as expected. However, when I do an async action, the stream closes and the file is no longer there. Removing the async action means that it works again. I need to do an async query to save the file in the correct place.
[Route("uploadFile")]
[AllowAnonymous]
public async void uploadFile()
{
var files = HttpContext.Request.Form.Files;
if (files != null)
{
var file = files.FirstOrDefault();
var fileName = file.FileName;
using (var input = file.OpenReadStream())
{
var id = "someId";
await Task.Delay(TimeSpan.FromSeconds(2));
// after doing this async action, the file and stream are no longer accessible.
...
I posted this as a question to the asp.net core team and had an answer here.
Don't use async void in your controller action. Use async Task instead so that the framework can wait until you are done.
I didn't expect the return type to impact this functionality, but well, now I know.