API Post 请求时出现文件上传错误:400

问题描述 投票:0回答:1

我有一个 API Post 方法,它获取 IFormFile 作为输入,并将文件上传到云存储。此代码在 localhost 上运行良好,但是当相同的 Post 操作在生产托管环境(核心容器化映像主机到 Kubernetes 集群)中抛出 400 错误时。

这是我的行动方法,

[HttpPost("")]
[Consumes("multipart/form-data")]
public async Task<ActionResult> UploadFileAttachmentAsync(IFormFile file)
{
    var result = await this.attachmentService.UploadAttachmentAsync(file);

    if (result != null)
    {
        return this.StatusCode(StatusCodes.Status200OK);
    }

    return this.StatusCode(StatusCodes.Status500InternalServerError);
}

当我从 Swagger UI、邮递员或任何地方的本地开发环境调用此 API post 操作时,它工作正常,我可以获取此操作的文件输入。 https://localhost:4242/附件

但是,当我使用托管 API 时,相同的操作调用不起作用, https://test-api.example.com/attachments

Swagger 输入就像, 邮递员输入,

收到 400 bad request 错误,

{
  "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
  "title": "Bad Request",
  "status": 400,
  "traceId": "00-7f70c739657ae91cccffdb47400cdf2f-0f3bd7b4bcce3774-00"
}

Iformfile 输入验证本身在这里失败了,请问我在托管环境中做错了什么吗?

asp.net-core-webapi iformfile
1个回答
0
投票

你有没有弄清楚这一点?我面临同样的问题,无法弄清楚。可能是这样的:https://github.com/dotnet/aspnetcore/issues/44765

© www.soinside.com 2019 - 2024. All rights reserved.