// helper methods private async Task <string> SetPathAndUpload(AnswerViewModel answerViewModel) { // for more advanced projects add a composite file provider - for now wwwroot // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/file-providers?view=aspnetcore-5.0#compositefileprovider string serverImagesDirectory = Path.Combine(_webHostEnvironment.WebRootPath, "uploads"); string uniqueFileName = _fileOperations.AssembleAnswerUploadedFileName(answerViewModel.UserId, answerViewModel.Image.FileName); string filePath = Path.Combine(serverImagesDirectory, uniqueFileName); await answerViewModel.Image.CopyToAsync(new FileStream(filePath, FileMode.Create)); return(uniqueFileName); }