The following code corresponds to a Blazor server-side page:
@page "/ShowFile/{Id:guid}"
//// What to put here to let the browser render the byte array stored on this.Model
//// Also how to specify the content type of the response?
@code
{
[Parameter]
public Guid Id { get; set; }
private byte[] Model { get; set; }
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
//// Gets the byte array of a file based on its identifier.
this.Model = await this.GetFile(this.Id).ConfigureAwait(false);
}
}
In ASP.NET MVC I used to do it in the controller action as:
this.Response.ContentType = "application/pdf"; //// Assuming that byte array represents a PDF document.
await this.Response.Body.WriteAsync(this.Model);
What can I do to let the browser to render the byte array in my page based on its content types?