Smalltalk/Seaside REST服务返回图像

4
我正在学习Smalltalk/Seaside,并尝试从REST服务返回一张图片。我正在阅读关于REST服务的Seaside书籍,其中有一个文件上传的例子book,但是没有关于如何从REST服务返回文件或图像的例子。
我在SO上找到了this,但我不知道如何在Seaside中实现它(尚未)。
作为概念证明或“可能起作用的最简单的事情”,我想返回一张从磁盘读取的图片。结果我想在网页上显示这个图像。有任何想法吗?
1个回答

1

我很晚了,但仍在做类似的事情。

创建名为ImageGetter的WARestfullHandler子类,并定义方法。

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

现在使用以下代码注册端点:

WAAdmin register: ImageGetter at: 'images' 

当调用images/getImage时,您将收到要在浏览器上显示的图像。

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

上述网址将为您提供更多选项/信息。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接