📜  .net core 3.1 中的 httppostedfilebase - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:17.585000             🧑  作者: Mango

代码示例1
[HttpPost("UploadFiles")]
public async Task Post(List files)
{
    long size = files.Sum(f => f.Length);

    // full path to file in temp location
    var filePath = Path.GetTempFileName();

    foreach (var formFile in files)
    {
        if (formFile.Length > 0)
        {
            using (var stream = new FileStream(filePath, FileMode.Create))
            {
                await formFile.CopyToAsync(stream);
            }
        }
    }

    // process uploaded files
    // Don't rely on or trust the FileName property without validation.

    return Ok(new { count = files.Count, size, filePath});
}