public static void getImage(String fileName) {
File file = new File("~/" + fileName);
response.contentType = "image/png";
renderBinary(file);
}
图像在这种方法的响应和renderBinary都出现错误如何显示在游戏框架2.1
public static void getImage(String fileName) {
File file = new File("~/" + fileName);
response.contentType = "image/png";
renderBinary(file);
}
图像在这种方法的响应和renderBinary都出现错误如何显示在游戏框架2.1
您正在使用是Playframework 1.x中的代码,它不与2.x版本兼容版。这两个版本完全不同。
正如@rags提到的,看看上的Content-Type How to render a binary with play 2.0?
的更多解释在这里可供选择:http://www.playframework.com/documentation/2.1.1/JavaResponse
公共静态结果的getImage()抛出IOException异常{ 档案文件=新的文件(“ d:\ Images \“+ name +”。jpg“);
return ok(org.apache.commons.io.FileUtils.readFileToByteArray(file)).as("image/jpeg");
}
我在这里,因为我使用的文件操作使用IOException异常,这是使用而非renderBinary
这不是在玩框架正常工作2.1 –
http://stackoverflow.com/questions/另一种方式8305853 /如何渲染的-A-二进制与播放-2-0 – rags