user920041
user920041

Reputation:

Hot to create a zip file with Play! Framework?

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?

Upvotes: 1

Views: 1378

Answers (4)

Julius Schorzman
Julius Schorzman

Reputation: 1432

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.

Upvotes: 0

emt14
emt14

Reputation: 4896

You can use Play helper class, Files.zip

Upvotes: 0

Crazenezz
Crazenezz

Reputation: 3456

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

Note: I'm using Play-1.2.3

Upvotes: 0

Aleksandr Kravets
Aleksandr Kravets

Reputation: 5947

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

Upvotes: 2

Related Questions