Created
June 27, 2019 10:15
-
-
Save felipebossolani/8e37f48003399fb75b5707545b5c94e6 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 = "https://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