2013-02-10 53 views
0

是否可以使用Luracast Restler来返回图像?像拨打电话:使用Restler返回图像

http://myserver.com/api/users/002/avatar 

要下载一个PNG?

回答

2

可以使用Restler为图像提供服务。

你需要做你的API方法如下

  • 设置内容类型标题为右图像类型(PNG,JPEG等)

    header("Content-Type: image/png"); 
    
  • 回声图像content

    示例

    $im = imagecreatefrompng("test.png"); 
    
    header('Content-Type: image/png'); 
    
    imagepng($im); //this sends the image as the response 
    imagedestroy($im); 
    
  • 使用退出或死亡,而不是阻止通常的返回结果

+0

这听起来比我是进入一个更容易的执行:扩展格式类服务PNG图片...谢谢 – Jelle 2013-02-12 18:49:41

+0

Imageloader http客户端将Accept头设置为image/*,现在Restler抱怨“内容协商失败。尝试'application/json'“。我应该添加一个空MIME =”image/*“的ImageFormat类吗?还是有更好的方法吗? – Jelle 2013-02-28 15:19:34

+1

是的,你需要添加一个伪ImageFormat类 – Luracast 2013-03-01 03:34:13