Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Httpclient.SendAsync loads StreamContent into memory before sending it to the server

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);
}
like image 399
Dezv Avatar asked Dec 19 '25 22:12

Dezv


1 Answers

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.

like image 60
Dezv Avatar answered Dec 21 '25 12:12

Dezv