How can a HttpConnection.ChunkedEncodingReadStream be stream directly to browser as PDF ?? PDF file can be as large as 200MB.
In snippet below, ChunkedEncodingReadStream is saved to temp file first, and then it will be returned to user in FileStreamResult.
FlurlRequest request = new (endpoint.Url);
using var response = await request.SendAsync(HttpMethod.Get, null, default(CancellationToken), HttpCompletionOption.ResponseHeadersRead)
.ConfigureAwait(false);
// HttpConnection.ChunkedEncodingReadStream
using Stream httpStream = await response.GetStreamAsync().ConfigureAwait(false);
int bufferSize = 4096;
// Save to temp file first, and serve that,
// will use Flurl DownloadFile instead.
var filePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
using FileStream fileStream = new (filePath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize, useAsync: true);
await httpStream.CopyToAsync(fileStream, bufferSize, new CancellationToken()).ConfigureAwait(false);
// will use FileStreamResult to "stream" filePath
return filePath;