Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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