I have a controller endpoint which serves files as follows;
[HttpGet]
[ProducesResponseType(typeof(FileStreamResult), 200)]
[Route("{documentId}")]
public IActionResult GetDocumentImage(int documentId)
{
var response = _service.Get(documentId);
HttpAssert.Success(response);
HttpAssert.IsNotNull(response);
Stream stream = new MemoryStream(response.Result.Data);
if (stream == null)
return NotFound();
return File(stream, response.Result.MimeType);
}
This works well when setting to src
on a img
tag and can confirm the files are being successfully sent.
I want to consume the result in a blazor
razor
page. I deserialise the call using
var responseContent = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
var result = JsonConvert.DeserializeObject<T>(responseContent);
return new ServiceResponse<T> { Result = result, HasError = false, HttpErrorCode = -1, Error = null };
}
However, when I deserialize to an object
(with JsonConvert.DeserializeObject<T>(responseContent)
)
An error is thrown with no ex.Message
when I debug and tried to evaluate in the watch window I get
'Unexpected character encountered while parsing value: %. Path '', line 0, position 0.'
The return in this situation is a PDF file. Can anyone direct me as to where I am going wrong please?