Created
June 27, 2019 09:45
-
-
Save felipebossolani/6697890b5023fb58a8d1d9ac6382eed8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
namespace AspNetCoreMultipleUploadAPI.ConsoleApp | |
{ | |
public class UploadRestClientModel | |
{ | |
private string BASE_URL = "http://localhost:44336/api/file/"; | |
public Task<HttpResponseMessage> Upload(List<FileInfo> fileInfos) | |
{ | |
try | |
{ | |
var httpClient = new HttpClient(); | |
var multipartFormDataContent = new MultipartFormDataContent(); | |
httpClient.BaseAddress = new Uri(BASE_URL); | |
foreach (var fileInfo in fileInfos) | |
{ | |
var fileContent = new ByteArrayContent(File.ReadAllBytes(fileInfo.FullName)); | |
multipartFormDataContent.Add(fileContent, "files", fileInfo.Name); | |
} | |
return httpClient.PostAsync("upload", multipartFormDataContent); | |
} | |
catch | |
{ | |
return null; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment