[Play 2.6-Java] Access images/files from template


I’m unable to access files (images or others) that aren’t in the application package.
I’m writing an application that needs to display/access images or files created dinamically and for the moment I’m unable to use its because Play doesn’t found its.
I would to use jsMol (a molecular viewer) that needs to access to files created dinamically from a template page. The files are stored in public folder but the template cannot access to this file.
I tried to use routes.Assets.versioned without success.

Is the a way to access to files/images stored in public folder in a production environment?


(Marcos Pereira) #2
public Result deliveryFile() {
  File file = findTheFileSomehow();
  return ok(file);

And of course you can customize headers such as Cache-Control, Etag, etc.



Thanks for you answer. But programs like jMol needs a file path where directly read a file. If I pass a file object jMol doesn’t work. Seems that everything not packaged isn’t unreachable by template.
Sure that isn’t possible to access to images/files in public folder that aren’t packaged?

(Marcos Pereira) #4

Hey @morellik,

Better to share your code then. From Play perspective, you can read a file from wherever you want and deliver it. Of course you need to care about Path Traversal attacks when not using Assets controller.

I’m not sure what are the constraints imposed by jMol.



This is the jsMol part. In the first line I’ve to set the path where is a file created dinamically by other tools.

 var script_tojsmol = "load " + <path_to_my_local_file>;

         info = {

             color: "#000000",
             height: 400,
             width: 650,

             use: "HTML5",
             script: script_tojsmol,
             defaultModel: null,
             addSelectionOptions: false,
             debug: true,
             j2sPath: '@routes.Assets.versioned("javascripts/j2s")'

         jmol_app = Jmol.getApplet("jmolApplet0", info);

If I substitute <path_to_my_local_file> with real path @routes.Assets.versioned(“structure_pub/P48454_cluster_1.pdb”)’ I’m able to see the protein in jsMol but only in development mode. In production doesn’t work.


I still trying to solve this issue without results. Someone can help me?

(Mahadi) #7

What will be the way in Scala? Because ok needs an implicit.

(Mahadi) #8

Have you got your problem solved? What is the way?


For the moment no solution for me.

(Mahadi) #10

you can follow this