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 it streams it as a web server?
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 it streams it as a web server?
Play 2.5
file: routes
file: ImagesController
In the interests of completeness, I've experienced this problem many times and there has been no sufficient answer for it.
Typically nginx would face the outside world and reverse-proxy back into the application server. You do not want to serve files straight from Play especially if you're building paths yourself which may present security risks. Let the experts handle static files, ie nginx.
Play Framework supports sbt-native-packager's "dist" directory which will attach any files in there right inside the distribution ZIP package [1]. Here is the documentation for that:
For use cases such as controlled downloads use nginx's X-Accel where via a response header you tell nginx what file to send back to the client.
TLDR: use nginx for what it's made for, use Play for what it's made for.
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:And then you have to define your assets controller. A simple example how it could be done:
A hacky solution would be to include in your sbt play public folder a symlink to the location you want to load the files. The symlink will be packaged in the assembly and will be functional at run time.
Now you can use in your routes file something like:
The downside of this is that your stage/dev/prod environment must have that content you need at the same location.