I need to return an image with a Web API Get method. The code below seems to work fine except that I get this message in the Fiddler's ImageView window, "This response is encoded, but does not claim to be an image."
public HttpResponseMessage Get()
{
using (FileStream fs = new FileStream(filePath, FileMode.Open))
{
HttpResponseMessage response = new HttpResponseMessage();
response.Content = new StreamContent(fs);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
return response;
}
}
I see the same result in the Fiddler with this code also:
public HttpResponseMessage Get()
{
HttpResponseMessage response = new HttpResponseMessage();
Byte[] b = (GetImageByteArray());
response.Content = new ByteArrayContent(b);
response.Content.LoadIntoBufferAsync(b.Length).Wait();
response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
return response;
}
I get the same result if I use .png format.
Appreciate your help,
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…