ASP.NET 5 / MVC6 上传的文件存放在哪里?

Where does ASP.NET 5 / MVC6 store uploaded files?

如果我上传一个文件并且它由 Microsoft.AspNet.Http.Features.Internal.FormFile 表示,它会存储在进程文件系统的任何位置,还是指向内存中存在的字节?

基于 HttpRequest.Body 内存流的 FormFile 对象。查看更多详情 github

var file = new FormFile(_request.Body, section.BaseStreamOffset.Value, section.Body.Length, name, fileName)
{
    Headers = new HeaderDictionary(section.Headers),
};

您可以调用 FormFile.SaveAs() 或 FormFile.SaveAsAsync() 将文件保存在文件系统中:

public class HomeController : Controller
{
    public IHostingEnvironment Hosting { get; set; }

    public async Task<IActionResult> Index(IFormFile file)
    {
        await file.SaveAsAsync(Path.Combine(Hosting.WebRootPath, "storage", "file.txt"));
        //...
    }
}