Play! framework 2.0: How to display multiple image?

后端 未结 1 1219
温柔的废话
温柔的废话 2021-01-03 09:16

I need to display a gallery of photos. So here is my template:

@(photos: List[Photo])

@title = {
  Gallery
}

@main(title,\"photo\"         


        
1条回答
  •  一生所求
    2021-01-03 09:56

    Take a look at my very similar question: Direct serving files from outside of Play directories structure , finally I used my second suggestion in very basic sample it can be showed as:

    public static Result serve(String filepath){
        // some stuff if required
        return ok(new File("/home/user/files/"+filepath));
    }
    

    route (use asterisk with *filepath to allow strings with slashes inside):

    GET   /files/*filepath    controllers.Application.serve(filepath : String)
    

    view (lack of @ character before photo.path is not accidental)

    @photo.alt
    

    edit:

    You of course don't need to serve files trough the controller if you have any HTTP server and ability to create new subdomain/alias pointing to directory. In such case you can just store links as http://pics.domain.tld/holidays_2012/1.jpg or even better as holidays_2012/1.jpg (and then prefix it in the template with subdomain).

    Finally you can set-up some alias ie. with Apache to use your domain.tld/* as pointer to Play app and domain.tld/pics/* as pointer to some folder

    
      ProxyPreserveHost On
      ServerName domain.tld
      ProxyPass  /pics !
      ProxyPass / http://127.0.0.1:9000/
      ProxyPassReverse / http://127.0.0.1:9000/
    
      Alias /pics/ /home/someuser/somefolder_with_pics/
      
        Order allow,deny
        Allow from all
      
    
    

    in such case it's important to place ProxyPass /pics ! before ProxyPass / http://...

    0 讨论(0)
提交回复
热议问题