Direct serving files from outside of Play directories structure

白昼怎懂夜的黑 提交于 2019-12-07 07:09:56

问题


ellou' Players

I need to crate custom CDN-like solution for small app purposes and wonder what is the best way to serving files directly with Play, but not placed under the public directory of the application? I need to gain access to FTP-upload folder.

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

What is the best way to serve file /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 HTTP server and set separate host or alias for ftp folder , but I would like to avoid using additional servers on some nodes (ref: if you're looking for server solution check the sample config).
  • Second is writing Application.serve(String filepath) action + route, but I don't need any additional actions before serving files. Is that make sense to use this approach?

Is there other option available?

(this question is also available at Google Groups)


回答1:


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

Note, if you define asset mappings outside “public,” you’ll need to tell sbt about it, e.g. if you want:

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

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

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

I did not test it, but it's worth a try :-)



来源:https://stackoverflow.com/questions/10787753/direct-serving-files-from-outside-of-play-directories-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!