Upload files in ASP.NET Core

Example code:

[HttpPost]
public async Task<IActionResult> UploadFile(IEnumerable<IFormFile> files)
{
    int fileCount = files.Count();
    if (fileCount != 1)
        return BadRequest(new ErrorMessage($"You can only upload exactly 1 file, you uploaded {fileCount}"));

    IFormFile file = files.First();
    string fileName = file.FileName;
    using MemoryStream stream = new MemoryStream();
    await file.CopyToAsync(stream);

    // Do something with the memory stream here

    return Ok();
}