I have a method in some micro service in C#:
[HttpGet]
[ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK, "application/pdf")]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> Get(long id, CancellationToken cancellationToken)
{
var result = await service.RenderIfExists(id, cancellationToken);
if (result is null)
{
return NotFound();
}
Response.Headers.Append("Access-Control-Expose-Headers", "Content-Disposition");
return File(fileContents: result,contentType: "application/pdf",fileDownloadName: $"lalala");
}
When I invoke this endpoint from Swagger, I can download the returned file.
I have to just invoke this endpoint from another micro service with GetStreamAsync and return the result as is. But I don't understand how. I also have to do this using stream to avoid saving result in LOH.
public async Task<IActionResult> Get(long id, CancellationToken token)
{
const string @base = "lalala";
var url = $"lalala";
var path = @base + url;
var stream = await httpClient.GetStreamAsync(path, token);
// ???
}
Results.Stream(Stream, ...)?