Help with serving images in production mode from Play

Hi all,

I have a problem serving files from the public folder in production mode.
The system will serve them fine in Dev mode.

I added import com.typesafe.sbt.packager.MappingsHelper._mappings in Universal ++= directory(baseDirectory.value / “public”) to build.sbt to include the Public directory.
When I run the dist command the public directory and the image files used in the menus etc. are all included in the distribution zip file.

The requirement here is that the Play instance has to serve the file.
Everything I’ve read says to offload this to Nginx but this is not possible in my use-case as the CDN server will be remote and there is a delay in serving the image from it.
This will result in the user not being able to view the image they’ve uploaded to the application instantly on redirect.
The plan is for Play to serve the file until the file-server has the file in which case it will be served from there.

The issue I am having is that the application writes images to a sub-directory in the Public directory but these are not being served.

For example the menu item images are served from /files/images and the route is GET /files/*file controllers.Assets.at(path="/public", file).
The directory the application writes to is dynamic so for example /public/images/item/N/pictures/, N is a number in this case and changes.

The path generated by the view for a menu image is "/files/images/image.jpg and it displays without issue.
The path generated by the view for an uploaded image is “/files/images/item/24/pictures/item_pic.jpg” for example and it will not display at all.

I’m using Play 2.5 at the moment.
Yes I need to upgrade but I don’t have time just yet.
One guy, a lot to do first :slight_smile: .

One the plus side Play is blistering fast in Production compared to Dev :smiley:

Thanks for any help you can give.
It has my head wrecked ;)

Assets.at serves only static content, there is no way to serve user uploaded files like that, you should write your own controller action if you want to serve user uploaded files from file system