Forwarding file stream to client in Blazor WebServer in .NET 8

I’m writing a Blazor WebServer application which, at one point, allows the client to download a file. This file is forwarded from another API, which offers it as an application/octet-stream message, and according to the code snippet found in https://learn.microsoft.com/en-us/aspnet/core/blazor/file-downloads?view=aspnetcore-8.0, the block of code responsible of initiating the download looks like this

// stuff
using var client = new HttpClient();
var response = await client.GetAsync(url_of_file);
if(response.IsSuccessStatusCode)
{
    var stream = await response.Content.ReadAsStreamAsync();
    var streamRef = new DotNetStreamReference(stream: result);
    await JS.InvokeVoidAsync("downloadFileFromStream", name_of_file, streamRef);
}
// stuff

Even though the files are not too big, I don’t quite like this way of proceeding, as I believe that response.Content.ReadAsStreamAsync is loading the full content of the response into memory before forwarding it to the client, as its result is a MemoryStream. This is not desirable, as it is introducing a delay before the download starts (the time required for the server to fully download the file), and I’m concerned of the impact to memory once several users try downloading at the same time.

I can’t just redirect the client to the API producing the file, which would seem to be the obvious solution, as part of the ‘raison d’être’ of my server is that the API is accessible through my application, but not by the end users. Is there an easy way for me to just forward to the client the result of the API request (i.e., kind of piping the content of response into a Stream without just fully loading it into memory all at once)?

What I tried:
The code provided is the last iteration of my attempts.

What I expected:
I expected that the Stream obtained at await response.Content.ReadAsStreamAsync() would be an IO stream with the data coming from the HTTP messages from the API.

What I found:
Instead, I found it to be a MemoryStream that contains the full result of the communication, which is not desirable, as I don’t want it to be fully placed into memory in my server, nor wait for it to be fully downloaded to the server before starting the download at the client.

New contributor

Evaristo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật