我有一个 Web 应用程序,它执行将图像上传到 api 的操作,代码如下
[HttpPost]
public async Task<IActionResult> Upload([FromForm] UploadModel model)
{
var upload = AccountApi.UploadFile(model);
return Ok("OK");
}
public static object UploadFile(UploadModel model)
{
RestClient client = InitClient();
request.Resource = "Account/UploadFile";
request.Method = Method.POST;
request.AddJsonBody(model);
IRestResponse<object> response = client.Execute<object>(request);
return response.Data;
}
public class UploadModel
{
public long UserId { get; set; }
public string Token { get; set; }
public IFromFile File { get; set; }
}
并且在这样的代码上方有一个 Web API 来处理 Rest 请求
[HttpPost("UploadFile")]
public async Task<object> UploadFileAction(UploadModel model)
{
// the code handle upload file request here
return "Success";
}
我的问题是 Web 应用程序中的 UploadModel 模型包含从前端请求的正确值(UserId = 10,Token = "eyJ........",File = [object])但是当它发布时对于 API,UploadModel 中的 3 个属性没有获得从 Web 应用程序发布的值(UserId = 0,Token = null,File = null)
你能帮我找到解决方案吗?谢谢大家