Play框架上公用文件夹外部的资产映射 [英] Asset mapping outside public folder on Play framework

查看:43
本文介绍了Play框架上公用文件夹外部的资产映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We have huge list of images that we need to store in an external path.. i.e outside of play application folder.

我们如何使它可以用作资产,以便将其作为Web服务器流化?

How can we make it available to play as an asset so it streams it as a web server?

推荐答案

您可能已经看过Play的

You've probably seen Play's documentation about Assets. Additionally to Play's standard assets you can define your own.

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

In conf/routes you need to add a line for your external asset:

# 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)

然后,您必须定义资产控制器.一个简单的示例:

And then you have to define your assets controller. A simple example how it could be done:

public class ExtAssets extends Controller {

    public Result at(String filePath) {
        File file = new File(filePath);
        return ok(file, true);
    }
}

这篇关于Play框架上公用文件夹外部的资产映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆