Handling dynamic created files in play 2

后端 未结 1 398
误落风尘
误落风尘 2021-01-06 19:39

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 /a

相关标签:
1条回答
  • 2021-01-06 20:04

    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

    0 讨论(0)
提交回复
热议问题