I have a function accessible through my REST API, configured with ASP.NET Web API 2.1, that should return an image to the caller. For testing purposes, I just have it returning a sample image I have stored on my local machine right now. Here is the method:
public IHttpActionResult GetImage()
{
FileStream fileStream = new FileStream("C:/img/hello.jpg", FileMode.Open);
HttpContent content = new StreamContent(fileStream);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/jpeg");
content.Headers.ContentLength = fileStream.Length;
return Ok(content);
}
When this method gets called, I am not getting an image back at all. Here is the response I am receiving:
{"Headers":[{"Key":"Content-Type","Value":["image/jpeg"]},{"Key":"Content-Length","Value":["30399"]}]}
Why am I not getting the image data back as part of the request? How can that be resolved?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…