IFormFile always return null in asp.net core 2.1

前端 未结 11 1841
伪装坚强ぢ
伪装坚强ぢ 2021-01-11 11:52

Api method is looks like below

    [HttpPost]
    public async Task> MediaBrand(IFormFile file, int brandId)
         


        
11条回答
  •  北海茫月
    2021-01-11 12:13

    Adding (Name = "body") to the from form worked for me

    Server Call:

    [HttpPost]
      [Route("UploadImage")]
    
    public IActionResult UploadImage([FromForm(Name = "body")]IFormFile formData)
    

    Client code:

    let formData = new FormData();
    formData.append('body', event.target.files[0]);
    
    const config = {
      headers: {
      'content-type': 'multipart/form-data',
      },
    }
    
    axios.post(ApiURL,formData, config);
    

提交回复
热议问题