ASPNetCore - Uploading a file through REST

前端 未结 2 1759
感动是毒
感动是毒 2020-12-28 18:22

I am using Insomnia for testing an API, but the same happens with Postman.

I want to test a file upload, with the following controller:

public async          


        
2条回答
  •  时光取名叫无心
    2020-12-28 19:06

    In addition of the above, in case of multipart file conversion to base64String you can refer to the below:

    if (File.Length> 0)
       {
           using (var ms = new MemoryStream())
           {
               File.CopyTo(ms);
               var fileBytes = ms.ToArray();
               string s = Convert.ToBase64String(fileBytes);                                    
           }
        }
    

    Note: I am using this code for .NET CORE 2.1

提交回复
热议问题