I am replacing a HttpHandler with a middleware service. I have all the code working except for returning the actual image. All the existing samples are for asp.net Core (or earlier) , but with asp.net core 1.1 the response object has change?
public async Task Invoke(HttpContext context)
{
var mediaType = new MediaTypeHeaderValue("image/jpeg");
mediaType.Encoding = System.Text.Encoding.UTF8;
context.Response.ContentType = mediaType.ToString();
byte[] results = some process that generates a byte array
Stream stream = new MemoryStream(results);
context.Response.Body = stream;
await _next.Invoke(context);
}
So how do we attach the byte array to the response object?