.NET Core 的 IFormFile 如何识别 .csv 文件?

How can .NET Core's IFormFile recognise a .csv file?

我正在尝试使用 Postman post 一个 .csv 文件,但是当我调试它时它总是有一个空值。

我检查了csv文件,它应该是有效的,我可以用Microsoft Office和Open Office打开它。

我在 Postman 中将其作为 form-databinary 发送,但均无效。

我尝试添加一个 [FromForm] 属性,就像在这个答案中一样:

我也试过 IFormFileCollection,但这也没有用。

下面是精简的代码,即使在这里它仍然收到一个空值

namespace csvApp.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class CsvController : ControllerBase
    {
        [HttpPost]
        public ActionResult Post(IFormFile csv)
        {
            return Ok(csv);
        }
    }
}

我错过了什么?

尝试“Match name attribute value to parameter name of POST method”?即,像这样的东西?

根据 Microsoft 文档,“Binding matches form files by name. For example, the HTML name value in must match the C# parameter/property bound (FormFile). For more information, see the Match name attribute value to parameter name of POST method section”。

当我没有将它作为参数传递给我的 Post 方法时,它起作用了,我是从 Request.Form.Files:

获取它的
[HttpPost]
public ActionResult Post()
{
    var file = Request.Form.Files[0];
    return Ok(file);
}