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
Adding this answer because those comments are easy to miss (like I nearly did).
Suggested by Jussi Palo (using a PhysicalFileResult):
[HttpGet]
public IActionResult Get()
{
return PhysicalFile(@"E:\\Test.jpg", "image/jpeg");
}
Suggested by Tseng (using an overload of the FileContentResult constructor that accepts a stream):
[HttpGet]
public IActionResult Get()
{
FileStream stream = File.Open(@"E:\\Test.jpg");
return File(stream, "image/jpeg");
}
For RL remember to check the file/resource exists, and return 404 if not.