Read FileStreamResult API response and return it as FileContentResult C# .Net 6

361 views Asked by At

I have an API which gets data from another API. This endpoint returns a "FileStreamResult" as the response. I need to read this response content from the other API and return it as "FileContentResult". How could I achieve this?

Endpoint - API 01

[HttpGet("user/{email}")]
public async Task<IActionResult> GetImage(string email)
{
    var image = await _imageService.GetImageAsync(fileName);

    return image == null
        ? NotFound()
        : File(image.FileStream, image.ContentType);
}

Reading data - API 02

var endPoint = $"/api/image/user/{email}";
var response = await _client.GetAsync(new Uri(endPoint, UriKind.Relative)).ConfigureAwait(false);

var data = await response.Content.ReadAsStreamAsync(); //This is how I thought to do it but this might be wrong

I get the correct response from the endpoint but I need to read the content and return it as a "filecontentResult".

0

There are 0 answers