Request.Files in ASP.NET CORE

前端 未结 3 1390
情歌与酒
情歌与酒 2020-12-18 17:51

I am trying to upload files using aspnet core using ajax request . In previous versions of .net i used to handle this using

 foreach (string fileName in Re         


        
3条回答
  •  没有蜡笔的小新
    2020-12-18 18:32

    What about this merge from two good solutions I came around :

    var myBytes  = await GetByteArrayFromImageAsync(Request.Form.Files[0]); 
    
    private async Task GetByteArrayFromImageAsync(IFormFile file)
    {
      using (var target = new MemoryStream())
      {
        await file.CopyToAsync(target);
        return target.ToArray();
      }
    }
    

提交回复
热议问题