IFormFile always return null in asp.net core 2.1

前端 未结 11 1845
伪装坚强ぢ
伪装坚强ぢ 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:37

    If you use javascript and FormData object you need set the name of each file to 'files'

    this.files.forEach((f) => {
             formData.append("files", f, `${this.path}/${f.name}`);
          }); 
    

    if you use other name in your post you need to set it in the attribute of the post method

    formData.append("someName", f, `${this.path}/${f.name}`);
    
     public async Task Post([FromForm(Name ="someName")] List files)
    

    Dont forget to set content-type

    'Content-Type': 'multipart/form-data'
    

提交回复
热议问题