我写了一个小应用程序,用 play 2.0 创建可下载的 pdf 文件
我想为公众服务。在我的开发环境中,我创建了一个文件夹 /assets/文件夹,一切正常。
现在,当切换到生产环境时,我发现 play 总是在我背后部署这些文件。
我真的必须编写一个自己的 Controller 来为这些文件提供服务吗?或者这里的方法是什么?
最佳答案
我在尝试提供使用 Assets Controller 动态创建的文件时也遇到了问题。我不知道这是否是为了某种缓存,但我最终编写了自己的 Controller ,现在它运行良好。
我的意思是,我将 Assets Controller 用于常规公共(public)文件,而对于动态生成的文件,我使用这个:
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);
}
}
路线是这样的:
GET /files/:file controllers.FileService.getFile(file: String)
GET /assets/*file controllers.Assets.at(path="/public", file)
对我来说很好用
关于image - 在 play 2 中处理动态创建的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13688567/