restsmalltalkseaside

Smalltalk/seaside REST service return image


I'm learning Smalltalk / Seaside and I'm trying to return a picture from a REST service. I'm reading the seaside book on REST services. There is an example in the book on file uploading, but there is no example on how return a file or an image from a REST service.

I found this here on SO, but I don't know how to implement this in seaside (yet).

As a proof of concept or 'the simplest thing that could possibly work' I want to return a picture which I read from disk. As a result I want to show the image on a webpage. Any ideas on how to do this.


Solution

  • Its late but still (was working on something similar)

    Create your WARestfullHandler sub-class say ImageGetter and define method

    getImage
        <get>
        <produces: 'image/png'>
        | file image |
        [ 
         file := (FileSystem workingDirectory / 'myImage.png') readStream binary.
         image := file contents ]
         ensure: [ file close ].
       ^ image
    

    Now register the endpoint using

    WAAdmin register: ImageGetter at: 'images' 
    

    on calling images/getImage you will receive the image to be displayed on browser.

    https://code.google.com/p/seaside/wiki/SeasideRest

    The above url will give you more options/info.