使用ASP.net核心web api发送多个文件

Sam*_*ath 3 c# asp.net asp.net-core-mvc asp.net-core

我需要发送多个文件到ASP.net核心webApi方法.我已经尝试过如下所示.但它总是显示为0 files.你能告诉我为什么?

[Route("api/[controller]/[action]")]
[Consumes("application/json", "application/json-patch+json", "multipart/form-data")]
public class DocumentUploadController : CpcpControllerBase
{
    [HttpPost]
    public async Task<List<string>> AddDocument(ICollection<IFormFile> files)
    {
        foreach (var f in files)
        {
            var stream = f.OpenReadStream();
            var name = f.FileName;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

邮差:

在此输入图像描述

但我可以发送1个文件,如下所示.它工作正常.

[HttpPost]
public async Task<string> AddDocument(IFormFile file)
{
        var stream = file.OpenReadStream();
        var name = file.FileName;           
}
Run Code Online (Sandbox Code Playgroud)

Jan*_*nak 6

更换钥匙file1通过files在邮递员.这个对我有用.