多部分请求返回415

时间:2019-04-22 12:09:34

标签: c# .net asp.net-core

我想在我的.net core 2.2 Web应用程序中实现多部分请求的终结点。端点应接收模型和图像。

[HttpPost]
[Consumes("multipart/form-data")]
public async Task<IActionResult> Post(Model request, IFormFile file)
{
        // some action
}

public class Model
{
        public string FirstProperty { get; set; }

        public string SecondProperty { get; set; }
}

此端点始终返回415(不支持的媒体类型)。我知道.net core 2.2(https://github.com/aspnet/AspNetCore/issues/4396)中的问题。是否有解决此问题的方法?

1 个答案:

答案 0 :(得分:2)

使IFormFile file为模型类的属性,并用属性Model request标记[FromForm]

相关问题