玩!上传图像并在 /assets/images 上将其投入生产

Play! upload images and make them available in production at /assets/images

From the docs:

When you package your application, all assets for the application, including all sub projects, are aggregated into a single jar, in target/my-first-app-1.0.0-assets.jar. This jar is included in the distribution so that your Play application can serve them. This jar can also be used to deploy the assets to a CDN or reverse proxy.

我在我的应用程序中上传了一些图片,在开发中一切正常,但在生产中却出现错误。

问题是,我需要 public/images 文件夹中的那些文件才能在页面上显示它们,但它在生产中不起作用。

如何让用户上传图片并在 /public/images 上提供它们?

我是否必须创建另一个资产路径或类似的路径?

注意:没有 post 编码,因为它只是来自文档的标准上传方法。

我做了什么:

我知道这可能只是一个愚蠢的解决方法。

GET         /images/:name                               controllers.ImageController.show(name: String)

我创建了一个简单的操作来提供图像,例如:

def show(name: String) = Action { implicit r =>
    val rootPath = Play.application.path
    val path = FileSystems.getDefault().getPath("/" + rootPath + "/public/images/");
    Logger.info("serving image: " + path.toString  + "/" + name )
    Ok.sendFile(new java.io.File(path.toString + "/" + name))
  }

基本上整个操作在开发中会失败,但在生产中有效。

部署后,我手动创建了文件夹,例如

 your_root/target/universal/stage/public/images

现在所有图片都可以在:

 /images/name_of_the_image

注:播放版本=2.4.x