在play 2中处理动态创建的文件 [英] Handling dynamic created files in play 2

查看:96
本文介绍了在play 2中处理动态创建的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个小应用程序,用play 2.0创建可下载的pdf文件

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

我想向公众提供这些文件。在我的开发环境中,我在
/ assets /文件夹中创建了一个文件夹,一切都运行良好。

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 ?

推荐答案

尝试使用资产控制器动态创建文件时,我也遇到了问题。我不知道它是否适用于某种缓存,但我最终编写了自己的控制器,现在它完美地运行了。

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.

我的意思是,我使用Assets控制器对于常规公共文件和我动态生成的文件,我使用这个:

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);
       }
}

路线如下:

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

它对我很有用

这篇关于在play 2中处理动态创建的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆