ident ident - 9 months ago 99
C# Question

C# HttpClient 4.5 multipart/form-data upload

Does anyone know how to use the

in .Net 4.5 with

I couldn't find any examples on the internet.

Answer Source

my result looks like this:

public static async Task<string> Upload(byte[] image)
     using (var client = new HttpClient())
         using (var content =
             new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture)))
             content.Add(new StreamContent(new MemoryStream(image)), "bilddatei", "upload.jpg");

              using (
                 var message =
                     await client.PostAsync("", content))
                  var input = await message.Content.ReadAsStringAsync();

                  return !string.IsNullOrWhiteSpace(input) ? Regex.Match(input, @"http://\w*\.directupload\.net/images/\d*/\w*\.[a-z]{3}").Value : null;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download