Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Asp.Net 5 Return Image

$
0
0

Hello Everyone,

I have a Asp.Net 5 Project with a Web Api Controller.

I would like to return an Image which I can than consume anywhere.

The Image does not display in the Browser, instead a json file shows up.

        [HttpGet]

        [Route("~/api/getimage/{imageid}")]

       publicasyncTask<HttpResponseMessage> GetImage(string imageid)

        {

           var imageidint = Convert.ToInt32(imageid);

           var firstOrDefault = _applicationDbContext.Images.FirstOrDefault(n => n.Id == imageidint);

           var stream = default(MemoryStream);

            stream = firstOrDefault == null ? newMemoryStream(_applicationDbContext.Images.FirstOrDefault(n => n.Id == 6).Data) : newMemoryStream(firstOrDefault.Data);

           var response = newHttpResponseMessage { Content = newStreamContent(stream) };

            response.Content.Headers.ContentType = newMediaTypeHeaderValue("image/png");

           return response;

        }

This Code used to work in previous Versions, but now I only get:

{"Version":{"Major":1,"Minor":1,"Build":-1,"Revision":-1,"MajorRevision":-1,"MinorRevision":-1},"Content":{"Headers":[{"Key":"Content-Type","Value":["image/png"]}]},"StatusCode":200,"ReasonPhrase":"OK","Headers":[],"RequestMessage":null,"IsSuccessStatusCode":true}

Is there a default Json Formatter, which I can override?

I would appreciate and help greatly, Thank You Kind blessings


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>