gpt4 book ai didi

c# - IFormFile 在 asp.net core 2.1 中总是返回 null

转载 作者:行者123 更新时间:2023-12-03 06:34:04 25 4
gpt4 key购买 nike

这是我上传文件的方式我的 Api 操作:

[HttpPost]
public async Task<BaseListResponse<MediaStorageModel>> MediaBrand(IFormFile file, int brandId)
{
var files = new List<IFormFile>();
files.Add(file);

var response = await this.Upload(files, "brand", brandId);

return response;
}

我的 postman 配置:
postman_config
我将我的 api 从 .NET Core 2.0 升级到 2.1,但我的代码不起作用
有人可以帮忙吗?

最佳答案

我遇到了同样的问题,我可以通过将“名称”命名参数应用于 FromForm 属性以及表单中文件字段的名称来解决它。它指定表单中的哪个字段绑定(bind)到方法参数。更改您的方法签名,如此处所示。

[HttpPost("status")]
public async Task<BaseListResponse<MediaStorageModel>> MediaBrand([FromForm(Name ="file")] IFormFile file, int brandId)

关于c# - IFormFile 在 asp.net core 2.1 中总是返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52837636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com