Filedownload & ZipOutputStream

asked 2018-10-16 15:24:52 +0800

IngoB gravatar image IngoB flag of Germany
256 6


I want to offer a download of multiple files, which are compressed. Since I have limited space on the hdd, I want to zip the files while downloading.
This seems to be possible, if you write to the response's output stream (Creating Zip file while client is downloading) / (Compress dynamic content to ServletOutputStream).

I tried to write directly to the outputstream, but it fails with: (illegal character (SyntaxError))

HttpServletResponse response = ((HttpServletResponse) Executions.getCurrent().getNativeResponse());
response.setHeader("Content-Disposition", "attachment;filename=test.zip");
try (ZipOutputStream out = new ZipOutputStream(response.getOutputStream())) {
    byte[] readAllBytes = Files.readAllBytes(Paths.get("test.xlsx"));
    ZipEntry zipEntry = new ZipEntry("test.xlsx");
    // You may add other files here if you want to
} catch (Exception e) {

Another, probably better option would be to use the Filedownload, but the only stream is an Inputstream.

Does anyone got an idea how to solve this? Thank you :)

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-10-17 16:49:16 +0800

MDuchemin gravatar image MDuchemin
1511 1 5
ZK Team

Hi Ingo,

Executions.getCurrent.getResponse() will return the response object associated with the current /zkau request. You cannot use this to start a file download because by the time you get access to this object, ZK have already written into it, and will write again. Furthermore, the /zkau request is not made by the browser navigation, but as an Ajax request by the client engine, which is not equipped to process a binary file (it only expects JSON data as a reply).This is a limited communication channel between ZK server and client.

This mean that you cannot use the execution HttpResponse to download a file. To do this, the FileDownload utils in ZK open a separate request to a different AU Extension (sort of mini-servlet). To write to response directly, you would need to do something similar and send the client to load from your own servlet, or your own AuExtension.

If you'd like more details on that part, I'd recommend contacting support.

link publish delete flag offensive edit


Thank you, I will try that :)

IngoB ( 2018-10-17 19:49:40 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2018-10-16 15:24:52 +0800

Seen: 8 times

Last updated: Oct 17 '18

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More