Question

I've got a solution that works, although I suspect there is a much more efficient way to do this... The end result is a photo of the subject is displayed on a web page. To get that, I have a ServiceStack service which returns a byte array, which I feed to an HttpHandler that takes the byte array and turns it into an image. This way I can set the src of an image to http://www.mydomain.com/httphandler.ascx?id and the image of the specific person will be displayed. What I was hoping was that I could bypass the HttpHandler and use ServiceStack to return the image to the web page. I can't find any good examples of this, but I believe I read that this is possible with ServiceStack. Is this possible?

Was it helpful?

Solution

The docs on Service Return Types shows how to return image responses, techniques which are used in ServiceStack's imgur.servicestack.net demo.

An alternative solution would be to get an industrial strength webserver like nginx to serve the static file instead, thus completely avoiding ServiceStack, ASP.NET or any managed .NET code, which you can do by writing to a static file and redirecting to it.

This is how you can configure nginx to serve all static files in /img/ and add cache headers to static files that have common web formats file extensions (ico|pdf|flv|swf|exe|txt|css):

server {
    listen 0.0.0.0:80;
    server_name myserver.net;

    root /home/src/myserver.net;

    location /img/ {
       alias /home/src/myserver.net/img/;
    }

    location ~* \.(ico|pdf|flv|swf|exe|txt|css) { 
       add_header        Cache-Control public;
       add_header        Cache-Control must-revalidate;
       expires           1d;
    } 

    location / {
        index index.html index.htm index.aspx default.htm default.aspx;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top