如何将IFormFile保存到磁盘?

我正在尝试使用这段代码将文件保存在磁盘上。

IHostingEnvironment _hostingEnvironment; public ProfileController(IHostingEnvironment hostingEnvironment) { _hostingEnvironment = hostingEnvironment; } [HttpPost] public async Task Upload(IList files) { foreach (var file in files) { var fileName = ContentDispositionHeaderValue .Parse(file.ContentDisposition) .FileName .Trim('"'); var filePath = _hostingEnvironment.WebRootPath + "\\wwwroot\\" + fileName; await file.SaveAsAsync(filePath); } return View(); } 

我能够用IHostingEnvironment替换IApplicationEnvironment,WebRootPath替换ApplicationBasePath

似乎IFormFile不再具有SaveAsAsync() 。 如何将文件保存到磁盘呢?

自核心发布候选人以来,一些事情发生了变化

 public class ProfileController : Controller { private IHostingEnvironment _hostingEnvironment; public ProfileController(IHostingEnvironment environment) { _hostingEnvironment = environment; } [HttpPost] public async Task Upload(IList files) { var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads"); foreach (var file in files) { if (file.Length > 0) { var filePath = Path.Combine(uploads, file.FileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(fileStream); } } } return View(); } }