[Route("api/[controller]/[action]"),ApiExplorerSettings(GroupName = "hello")] [ApiController] public class UploadFileController : ControllerBase { public UploadFileController() { } [HttpPost] public string UploadSingle(UploadReqModel ufile) { try { var file = ufile.file; string key = string.IsNullOrEmpty(ufile.key) ? "def" : ufile.key; return new QiNiuUpload.UploadFilesHelper().UploadFile(file, ufile.key, ufile.isPrivate); } catch (Exception ex) { new LogHelper().Error(ex, string.Format("{0}.{1}:", RouteData.Values["controller"].ToString(), RouteData.Values["action"].ToString()) + ex.Message); return JsonHelper.Instance.Serialize(new { errcode = 500, errmsg = "上传失败!" }); } }
前端请求结果如下:
接口传参没有问题,上传的图片对象也有。
排除一轮后发现我使用了ApiControllerAttribute特性,它有自动模型状态验证的功能,会自动验证传入的model.
去除[ApiControllerAttribute]就可以成功上传图片了。
asp.net core 上传图片接口返回The input was not valid
原文:https://www.cnblogs.com/is404/p/12420837.html