示例#1
0
        // helper methods
        private async Task <string> SetPathAndUpload(QuestionViewModel questionViewModel)
        {
            // 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");
            var    uniqueFileName        = _fileOperations.AssembleQuestionUploadedFileName(questionViewModel.UserId, questionViewModel.Image.FileName);
            string filePath = Path.Combine(serverImagesDirectory, uniqueFileName);
            await questionViewModel.Image.CopyToAsync(new FileStream(filePath, FileMode.Create));

            return(uniqueFileName);
        }