2

I'm trying to perform a large video upload to a server, but no matter what I do, if I'm using Httpclient.SendAsync(HttpResponseMessage) to send the content I have assigned to the HttpResponseMessage among with all the headers and such, the whole content will be loaded into the memory.

But I'm using HttpClient.PostAsync(uri, HttpResponseMessage.Content), it'll do the upload normally, without loading the content into the stream.

Is there any workaround, rather than just switch to PostAsync? It doesn't offer me the possibilities SendAsync offers, so I'd rather not do.

Example:

{
    var multiForm = new MultipartFormDataContent(UploadId);
    var fileStream = File.OpenRead(videoPath);
    var streamContent = new StreamContent(fileStream);
    multiForm.Add(streamContent, "video", Path.GetFileName(fs.Name));

    var request = GetHttpReqeustMessage[Method.Post, uri];
    request.Content = multiForm;

    var result = client.SendAsync(request);
}
Dezv
  • 156
  • 1
  • 8
  • `PostAsync` just calls `SendAsync` under the covers with a new `HttpRequestMessage` that has `HttpMethod.Post` set as the method. If there's a behavioral difference, it's due to properties in your message that are set differently. – Jeroen Mostert Oct 16 '19 at 15:15
  • I'd hate to see what `GetHttpReqeustMessage` (sic) is defined as in order for the remainder of that line to be valid C#. Multi-dimensional indexers are rarely encountered. – Damien_The_Unbeliever Oct 16 '19 at 15:24
  • 1
    Thank you! I am aware of this. And how so? What do you think would be the factors for the behavioral difference? On my tests, there are literally no changes of code, other than a user-agent assigned to the HttpRequestMessage's headers. Besides that, I have tried without headers, cookies nor anything else, the result is still the same, even though the requests matched... So annoying. – Dezv Oct 16 '19 at 15:25

1 Answers1

1

I'm so dumb. I forgot I was tracking the logs for every httprequestmessage, so I'd print everything within a request, including the bytes of the whole video. I want to fly, far away.

Dezv
  • 156
  • 1
  • 8