这是我上传文件的方式我的 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 配置:
我将我的 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/