Asp.net core .net核心web api上载文件失败,请求失败
我正在尝试使用.net core 2.1 web api将几个文件上载到web api端点 这是我的控制器和上传方法Asp.net core .net核心web api上载文件失败,请求失败,asp.net-core,.net-core,asp.net-core-webapi,Asp.net Core,.net Core,Asp.net Core Webapi,我正在尝试使用.net core 2.1 web api将几个文件上载到web api端点 这是我的控制器和上传方法 [Produces("application/json")] [Route("api/[controller]")] [ApiController] public class PagosController : ControllerBase{ [HttpPost("UploadDescuento")] public async Task<IA
[Produces("application/json")]
[Route("api/[controller]")]
[ApiController]
public class PagosController : ControllerBase{
[HttpPost("UploadDescuento")]
public async Task<IActionResult> UploadDescuento(IEnumerable<IFormFile> files)
{
return Ok();
}
}
但是我收到了一个坏请求
{
"": [
"The input was not valid."
]
}
你没有上传文件。您只是在客户端机器上发送文件的路径,服务器无法对其执行任何操作(除非服务器和客户端机器始终相同)
邮递员确实可以选择正确发送文件。请参阅。我的解决方案是删除ApiController的属性我不知道为什么文档没有说太多[我不了解问题出在哪里]
[Produces("application/json")]
[Route("api/[controller]")]
//[ApiController]<<remove this
public class PagosController : ControllerBase
[产生(“应用程序/json”)]
[路由(“api/[控制器]”)]
//[ApiController]您需要在postman的正文中选择表单数据,并设置一个键“files”作为文件类型我想,我做到了,您可以在postman创建的请求中看到“Content Disposition:form data;name=“files”;filename=“/C:/Users/jcpc9/Pictures/101-2621x1747.jpg”选择从计算机上载特定文件,您将以字节形式发送文件,但不要仅以字符串形式发送文件的位置
[Produces("application/json")]
[Route("api/[controller]")]
//[ApiController]<<remove this
public class PagosController : ControllerBase
[HttpPost("UploadDescuento")]
public async Task<IActionResult> UploadDescuento(IEnumerable<IFormFile> files)