What’s the best way to serve an image from ServiceStack when the file does not have an extension and is not recorded anywhere while ensuring all common browsers (including IE) display the image inline? The HelloImage examples seem to default to PNG which concerns me that there would be a mismatch. They also cause Chrome and IE to behave differently (Chrome displays inline / IE prompts to download).
Geoffrey Huntley:
Override the Response.ContentType manually and return a HttpResult:
public object Get(GetEmployeeAvatar request)
{
var photo = EmployeePhoto.GetEmployeeThumbnailPhoto(new MailAddress(request.EmployeeEmailAddress));
const string contentType = “image/png”;
base.Response.ContentType = contentType;
return new HttpResult(photo, contentType);
}
Darren Reid:
I think Internet Explorer is tied to the systems registry, where as Chrome might handle some of the known content types itself, not sure. On my PC, image/png in the example services works fine on IE. Content type of image/jpg works on Chrome, but not IE as my machine has *.jpg registered with content type image/jpeg, not image/jpg. Have a look in “HKEY_CLASSES_ROOT.png\Content Type” in the registry to see what value is being used.
Some one having a similar issue here -> http://answers.microsoft.com/en-us/ie/forum/ie9-windows_7/cannot-view-png-pages-in-internet-explorer/59070ae6-6521-4884-8e71-66571acaed4e
Example services I used for testing.
https://github.com/Layoric/SS-ImageTesting
I’ve just added several different examples of return an Image in ServiceStack in different image formats: https://github.com/ServiceStack/Test/blob/master/src/Test/Test/Test.ServiceInterface/ImageService.cs
I’ve tested a lot ofthe different combinations with IE and I’m not seeing any issues with it.
You can play with these services at: test.servicestack.net, e.g: http://test.servicestack.net/image-draw/ServiceStack?background=purple&foreground=yellow&width=900&height=600