Asset mapping outside public folder on Play framework

后端 未结 4 1304
悲哀的现实
悲哀的现实 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:49

    Play 2.5

    file: routes

    GET  /external_resources/*file controllers.ImagesController.getImage(path="/home/project_name/external/images", file: String)
    

    file: ImagesController

    package controllers;
    
    import play.mvc.Controller;
    import play.mvc.Result;
    
    import java.io.File;
    
    /**
     * Created by js on 6/1/17.
     */
    public class ImagesController extends Controller {
    
    public Result getImage(String path, String image) {
        System.out.println(path);
        System.out.println(image);
        image = image.replace("%20", " ");
        File file = new File(path + image);
    
        return ok(file);
      }
    }
    

提交回复
热议问题