2013-02-22 62 views
0

我想通过使用Play Framework的BufferedArray呈现图像。这些图像没有通过以下任何方式呈现。任何指针是真正有用的内联图像不适用于Play Framework 2.1

  1. 返回字节[]从豆,并使用@ bean.property在main.scala渲染。我可以通过查看源查看数据。
  2. 写了图像临时位置,并使用“>标签,没有成功返回的URL。
  3. 二手内嵌图像的方法(http://en.wikipedia.org/wiki/Data_URI_scheme)(有和没有Base64编码和图像文件大小小于32KB),但仍然没有运气。

任何帮助/指针真的很感激。

回答

0

我使用玩!框架2.1.0让,图像位于D:\\Images\\juventus.jpg(我的Windows用户)。以下是解决方案您的问题:

public static Result showImage() { 
    try { 
     byte[] array = Files.toByteArray(new File("D:\\Images\\juventus.jpg")); 
     return ok(array); // render image 
    } catch (IOException e) { 
     Logger.error("An IO Exception is occured while reading file!"); 
    } 
    return internalServerError("An IO Exception is occured while reading file!"); 
} 

这应该呈现图像作为响应。可能这篇文章很有用..;)

+0

这里是我的解决方案:http://stackoverflow.com/a/20838010/554796 – Benchik 2013-12-30 10:54:41