This extension is held as simple as possible. All input variables are self-explanatory besides the ContentName which is mainly the name of your binary. The used C# code looks as following.
public static async void UploadImage2(string url, byte[] imageData, string url_params, string mediaType, string filename, string contentName)
{
try
using (var client = new System.Net.Http.HttpClient())
using (var content = new System.Net.Http.MultipartFormDataContent())
var imageContent = new System.Net.Http.ByteArrayContent(imageData);
imageContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(mediaType);
content.Add(imageContent, contentName, filename);
var response = await client.PostAsync($"{url}?{url_params}", content);
response.EnsureSuccessStatusCode();
var responseContent = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseContent);
}
catch (Exception ex)
Console.WriteLine($"An error occurred: {ex.Message}");
add customized file upload