ASP.NET 核心 WEB API - 在 post 请求中接收多个文件

ASP.NET Core WEB API - Receive multiple files in post request

这是我的控制器操作:

// POST: api/Customers/Create
[HttpPost(), Route("Create")]
public async Task<ActionResult> CreateAsync([FromForm] CustomerModel model)

它收到一个 CustomerModel:

public Guid? Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string PhoneNumber { get; set; }
public string Email { get; set; }
public bool? IsActive { get; set; }
public  List<CustomerLicenseModel> LicenseFiles { get; set; }

我的 CustomerModel 有一个自定义 class,它是 CustomerLicenseModel

类型的文件列表
public  List<CustomerLicenseModel> LicenseFiles { get; set; }

这是 CustomerLicenseModel:

public class CustomerLicenseModel
{
    public LicenseFileType LicenseFileType { get; set; }
    public IFormFile LicenseFile { get; set; }
}

LicenseFileType 可以是正面或背面。

public enum LicenseFileType
{
    Front,
    Back
}

我如何通过 http 请求发送这个?

如果我的 CustomerModel 中有一个 List<IFormFile>,我可以通过 postman 或 swagger 发送多个文件,例如,但我需要知道 LicenseFileType 是什么。

有人可以帮忙吗?

Swagger默认不支持这种格式的传输,建议使用postman发送requset。