Direct file transfers from outside the Play directory structure

Players

ellou '

I need to build a custom CDN solution for small applications and wonder what is the best way to serve files directly using Play, but not placed in the public directory of the application? I need to access FTP upload.

Let's say that my application starts from the folder /home/myaccount/playapps/app201 and is available at http://somedomain.tld . I also have a shared FTP account with a folder pointing to /home/myaccount/ftp_upload .

What is the best way to work with /home/myaccount/ftp_upload/folder_1/sub_2/file.txt as http://somedomain.tld/ftp_upload/folder_1/sub_2/file.txt (without any checks and restrictions)?

  • One option is to use an HTTP server and install separate host or alias for the ftp folder , but I would like to avoid using additional servers on some nodes ( ref: check the sample configuration for a server solution).
  • The second entry is Application.serve(String filepath) action + route, but I don’t need any additional actions before executing the files. Does it make sense to use this approach?

Is there any other option?

(this question is also available on Google Groups )

+4
source share
1 answer

If your Play folder and FTP folder are on the same host, you can use public assets. From the documentation :

Note that if you define asset mappings outside of "public", you need to tell sbt about it, for example. if you want to:

 GET /assets/*file controllers.Assets.at("/public", file) GET /liabilities/*file controllers.Assets.at("/foo", file) 

you should add this to your project settings in project/Build.scala

 // Add your own project settings here playAssetsDirectories <+= baseDirectory / "foo" 

I have not tested it, but it's worth a try :-)

+2
source

Source: https://habr.com/ru/post/1414746/


All Articles