© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
4 replies
realivanjxツ

✅ httpclient get download stream in blazor

i have this code to download a file from remote source (about 100 MB).
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, REMOTE_URL);
HttpResponseMessage responseMessage = await Http.SendAsync(
    requestMessage,
    HttpCompletionOption.ResponseHeadersRead);
using Stream remoteStream = await responseMessage.Content.ReadAsStreamAsync();
byte[] buffer = new byte[1024 * 1024];

while (CurrentProgress < MaxProgress)
{
    int read = await remoteStream.ReadAsync(
        buffer,
        0,
        buffer.Length);
    CurrentProgress += read;
    StateHasChanged();
}
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, REMOTE_URL);
HttpResponseMessage responseMessage = await Http.SendAsync(
    requestMessage,
    HttpCompletionOption.ResponseHeadersRead);
using Stream remoteStream = await responseMessage.Content.ReadAsStreamAsync();
byte[] buffer = new byte[1024 * 1024];

while (CurrentProgress < MaxProgress)
{
    int read = await remoteStream.ReadAsync(
        buffer,
        0,
        buffer.Length);
    CurrentProgress += read;
    StateHasChanged();
}

but it seems that that code above downloads the whole file first at line
using Stream remoteStream
using Stream remoteStream
so i cant really show any progress to the gui. is this a bug with the blazor's httpclient implementation because the code works fine on my wpf app. thanks
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ HttpClient Base Address Null in Blazor WASM
C#CC# / help
16mo ago
✅ HttpClient Get Page Content
C#CC# / help
3y ago
❔ Need Help with httpclient Async stream reading
C#CC# / help
4y ago
Blazor Server: Cannot access a closed Stream
C#CC# / help
2y ago