Play框架上公共文件夹外的资产映射

Nis*_*ani 5 playframework playframework-2.2

我们有大量的图像列表需要存储在外部路径中...即在播放应用程序文件夹之外.

我们如何才能将其作为资产播放,以便将其作为Web服务器进行流式传输?

Kri*_*ris 7

您可能已经看过Play 有关Assets文档.除了Play的标准资产,您还可以定义自己的标准资产.

conf/routes你需要添加一行为您的外部资产:

# Static resources (not managed by the Play framework)
GET     /my_external_assets/*file         controllers.ExtAssets.at(file)
# Play's standard assets
GET     /assets/*file                     controllers.Assets.at(path = "/public", file)
Run Code Online (Sandbox Code Playgroud)

然后你必须定义你的资产控制器.如何做到这一点的简单例子:

public class ExtAssets extends Controller {

    public Result at(String filePath) {
        File file = new File(filePath);
        return ok(file, true);
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 这安全吗?当 filePath 设置为“../conf/application.conf”时说 (3认同)