IFormFile always return null in asp.net core 2.1

Herman picture Herman · Oct 16, 2018 · Viewed 11.5k times · Source

Api method is looks like below

    [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;
    }

My postman configuration enter image description here

Upgrade my dotnet core from 2.0 to 2.1 thie become not working, can anyone help about this. What going wrong

Answer

Ram Kumaran picture Ram Kumaran · Jan 21, 2019

I've faced the same issue, I was able to fix it by applying the 'Name' named parameter to FromForm attribute with name of the File field in the form. It specifies which field in the form to bind to the method parameter. Change your method signature as shown here.

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