0
public static void getImage(String fileName) {
        File file = new File( "~/" + fileName );
        response.contentType = "image/png";
        renderBinary( file );
    }

在此方法中,响应和 renderBinary 显示错误

4

2 回答 2

1

您使用的代码适用于 Playframework 1.x,它与 2.x 版本不兼容。这两个版本完全不同。

正如@rags 提到的,看看How to render a binary with play 2.0?

有关 Content-Type 的更多说明,请参见此处:http ://www.playframework.com/documentation/2.1.1/JavaResponse

于 2013-07-26T09:53:53.233 回答
1

public static Result getImage() throws IOException { File file = new File("d:\Images\"+name+".jpg" );

    return ok(org.apache.commons.io.FileUtils.readFileToByteArray(file)).as("image/jpeg");
}

这里我使用 IOException 因为我使用的是文件操作,这是使用的另一种方式,而不是 renderBinary

于 2013-07-29T07:42:07.670 回答