2

Consider this small code below:

var client = new HttpClient();
var multiForm = new MultipartFormDataContent();
var str = new StreamContent(File.OpenRead("movie.mp4"));
multiForm.Add(str, "to_upload", "1.mp4");
var response = await client.PostAsync("https://example.com/upload", multiForm);

As you can see I'm using StreamContent and MultipartFormDataContent to upload a file. My question is it is possible to somehow get the upload progress from HttpClient? Or any other way to get upload progress?

Hirbod Behnam
  • 577
  • 2
  • 7
  • 26

1 Answers1

2

You can make use of ProgressableStreamContent from here

or this answer

and a simple usage can be

 var progress = new ProgressableStreamContent (
     requestContent, 
     4096,
     (sent,total) => {
        Console.WriteLine ("Uploading {0}/{1}", sent, total);
    });
HariHaran
  • 3,642
  • 2
  • 16
  • 33