从远程服务器播放框架返回图像 java

Returning image from remote server play framework java

我试过return如下图:

return 好的(新文件(http://example.com/dpa/client_name/images/client_log.jpg"));

但是控制器中的方法无法从远程服务器获取图像并抛出图像未找到异常。

如何使用 java 播放框架从远程服务器检索图像并 return 作为响应?

只需使用 WS API

package controllers;

import play.libs.ws.WSClient;
import play.mvc.Controller;
import play.mvc.Result;

import java.util.concurrent.CompletionStage;
import javax.inject.Inject;


public class HomeController extends Controller {

    @Inject WSClient ws;

    public CompletionStage<Result> index() {
        return ws
          .url("http://www.maine-coon-cat-nation.com/image-files/orange-maine-coon-cat.jpg")
          .get()
          .thenApply(file -> ok(file.getBodyAsStream()).as("image/jpeg"));
    }

}