ASP .net Web Api downloading and viewing images
asp.net-web-api, c#, rest
Solution
Don't use the "attachment" content disposition header. Using that header instructs browsers to download the specified file instead of showing it inline.
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
Problem
I want to download images from a server and display them in the browser. But when I enter the url in the browser (localhost:port/api/service/imageID), the download box appears asking me wether to save or open the image. But I want the image to be straight displayed in the browser. This is my controller 'Get' method: ``` public HttpResponseMessage Get(int id) { HttpResponseMessage response; var image = _repository.RetrieveImage(id); if (image == null) { response = new HttpResponseMessage(HttpStatusCode.NotFound); } else { response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StreamContent(new MemoryStream(image.ImageData)); response.Content = new ByteArrayContent(image.ImageData); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentDisposition.FileName = image.OriginalFileName; response.Content.Headers.ContentType = new MediaTypeHeaderValue(image.Mime); response.Content.Headers.ContentLength = image.ImageData.Length; } return response; ``` Thanks a lot for any help