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;
}
Upgrade my dotnet core from 2.0 to 2.1 thie become not working, can anyone help about this. What going wrong
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.
In my case, i had an angular 6 app using a custom HttpInterceptor which adds content-type of "application/json" to every Http request along with a token before sending to an api. Something like below. Remove the line with 'Content-Type':
application/json
. Without that none of the solution here works. .Net Core is smarter now to translate whatever object u are sending to the api so far it matches the model u create for the object in angular.If you use javascript and FormData object you need set the name of each file to 'files'
if you use other name in your post you need to set it in the attribute of the post method
Dont forget to set content-type
Adding (Name = "body") to the from form worked for me
Server Call:
Client code: