Hot to create a zip file with Play! Framework?

2019-08-14 02:50发布

I have a bunch of public assets that I would like to zip and provide for download.

Is there an easy way in Play! to create a zip for a list of files/folders?

4条回答
一夜七次
2楼-- · 2019-08-14 03:26

I suppose you can always use Java libraries. See JavaDocs for details

查看更多
Anthone
3楼-- · 2019-08-14 03:26

play war "project_dir" -o "war_file_name" --zip

Note: I'm using Play-1.2.3

查看更多
ゆ 、 Hurt°
4楼-- · 2019-08-14 03:26

In the controller use this:

public class Public extends Controller {
  public static void download() {
    File dir = VirtualFile.fromRelativePath("/dir-to-zip/").getRealFile();
    File zip = VirtualFile.fromRelativePath("/files.zip").getRealFile();
    Files.zip(dir, zip);
    renderBinary(zip);
  }
}

Then add this to your routes file:

*        /download                 Public.download

Note that file paths are from your application root, not your file system root.

查看更多
smile是对你的礼貌
5楼-- · 2019-08-14 03:42

You can use Play helper class, Files.zip

查看更多
登录 后发表回答