Last post Nov 24, 2016 08:29 PM by Guy Gallant
Nov 24, 2016 08:29 PM|Guy Gallant|LINK
I am replacing a HttpHandler with a middleware service. Previously I used a httpHandler to read images from SQL and then return the byte array using the
following <img src='site/bldImage.ashx' />
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; // Does not work
await _next.Invoke(context); }
So the main question is how do I assign my byte array to the response object.
Maybe I could be pointed to an example.