Created
September 21, 2020 03:59
-
-
Save scattered-code/31d6e26e12f8d5c826423d83f6582e19 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"); | |
_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", multipartContent); | |
response.EnsureSuccessStatusCode(); | |
} | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment