Wie speichere ich IFormFile auf der Festplatte?
Ich versuche, eine Datei mit @ auf der Festplatte zu speicherdieses Stück Code.
IHostingEnvironment _hostingEnvironment;
public ProfileController(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
[HttpPost]
public async Task<IActionResult> Upload(IList<IFormFile> 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();
}
Ich konnte @ ersetz IApplicationEnvironment mit IHostingEnvironment, und ApplicationBasePath mit WebRootPath.
Wie es scheint IFormFile hat keinSaveAsAsync () nicht mehr. Wie speichere ich dann die Datei auf der Festplatte?