3

I wrote a small app that creates downloadable pdf files with play 2.0

I want to serve them to the public. On my development environment I created a folder in the /assets/ folder and everything worked nice.

Now, when switching to production, I figured out that play always deployed those files behind my back.

Do I really have to write a own controller to serve those files or what is the way here ?

1
  • I do not understand your question. You create those files and store them in a folder? Why not render on the fly? Dec 3, 2012 at 20:55

1 Answer 1

5

I've also had problems trying to serve files created dynamically with the assets controller. I don't know if it's for some kind of caching but I ended up writing my own controller, and now it woks perfectly.

I mean, I use the Assets controller for regular public files and for my dynamic generated files I use this one:

public class FileService extends Controller {
       static String path = "/public/dynamicfiles/";
       public static Result getFile(String file){
              File myfile = new File (System.getenv("PWD")+path+file);
              return ok(myfile);
       }
}

And the routes would be like this:

GET     /files/:file           controllers.FileService.getFile(file: String)
GET     /assets/*file               controllers.Assets.at(path="/public", file)

It works great for me

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.