Asset mapping outside public folder on Play framework

后端 未结 4 1210
悲哀的现实
悲哀的现实 2021-01-18 20:26

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

How can we make it available to play as an asset so i

4条回答
  •  感情败类
    2021-01-18 20:34

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

    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);
        }
    }
    

提交回复
热议问题