0

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".

Hash_Dew
  • 313
  • 1
  • 8
  • Wouldn't it just be a difference of using the File() helper with a string instead of a stream? – Devon Bessemer Jun 28 '23 at 19:42
  • "I need to read the content and return it as a "filecontentStream"" return it where? What do you need to return, what format? A string, a stream of bytes, something else? – Charlieface Jun 28 '23 at 19:58
  • @Devon I need to read the stream and return it as "filecontentResult" – Hash_Dew Jun 28 '23 at 20:01
  • @Charlieface Response gives an image file as a "FileStreamResult" I need to transform it to "filecontentStream". – Hash_Dew Jun 28 '23 at 20:05
  • Not sure what you mean. `data` is just a `Stream`, that will work anywhere you need a stream. What class is `FileContentStream` and why do you need it? – Charlieface Jun 28 '23 at 20:51
  • @Hash_Dew you need to use a stream reader and assign the result to a string. Research "how to read a stream into a string" – Devon Bessemer Jun 30 '23 at 13:15

0 Answers0