Created
September 21, 2020 17:47
-
-
Save scattered-code/7941f8fb6a2f574b87624b8388d5bd9f 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 Newtonsoft.Json; | |
using System; | |
using System.Collections.Generic; | |
using System.IdentityModel.Tokens.Jwt; | |
using System.IO; | |
using System.Net.Http; | |
using System.Net.Http.Headers; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace Misc | |
{ | |
class Program | |
{ | |
static string baseUrl = "http://localhost:39720"; | |
static async Task Main(string[] args) | |
{ | |
var _multipartHttpClient = new HttpClient { BaseAddress = new Uri(baseUrl), Timeout = new TimeSpan(0, 20, 0) }; | |
var multipartContent = new MultipartFormDataContent("NKdKd9Yk"); | |
multipartContent.Headers.ContentType.MediaType = "multipart/form-data"; | |
var videoContent = new StreamContent(new FileStream(@"C:\repo\test-files\test.mp4", FileMode.Open), 100000); | |
multipartContent.Add(videoContent, "video", "file.mp4"); | |
var thumbnailContent = new StreamContent(new FileStream(@"C:\repo\test-files\test.png", FileMode.Open), 100000); | |
multipartContent.Add(thumbnailContent, "thumbnail", "file.png"); | |
var progressContent = new ProgressableStreamContent(multipartContent, 100000, (done, total) => | |
{ | |
Console.WriteLine($"Done {done}/{total}"); | |
}); | |
_multipartHttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("multipart/form-data")); | |
_multipartHttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await GetToken()); | |
var response = await _multipartHttpClient.PutAsync($"{baseUrl}/api/files/upload", progressContent); | |
response.EnsureSuccessStatusCode(); | |
} | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment