我需要将图像作为API响应发送。我创建了一个响应,但仍然无法发送图像。我在Java中使用play框架。
Http.Response response = new Http.Response();
response.setContentType("image/jpeg");
谢谢。
最佳答案
不太清楚您使用的是哪个游戏版本,但这应该适用于2.X
public static Result returnImage(){
return ok(new File("public/img/1.jpg")).as("image/jpg");
}
在这里您可以看到ok()可以接收File作为参数。要检查所有选项,您可以转到Play Framework JavaDocs。
希望能帮助到你!