Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You shouldn't need to write the files first. You can create a zip file.</p> <pre><code>FileOutputStream fos = new FileOutputStream(zipFileName); zipOutStream = new ZipOutputStream(fos); </code></pre> <p>Then you can add entries for each of the files you are reading from the database</p> <pre><code>ZipEntry zipEntry = new ZipEntry("NameOfFileToBeAdded"); zipOutStream.putNextEntry(zipEntry); zipOutStream.write(byteArrayOfFileEntryData); zipOutStream.closeEntry(); </code></pre> <p>Of course the writes could be done in a loop so the byteArrayOfFileEntryData won't use up all the server memory.</p> <p>Once all the zip entries are added, close the zip file</p> <pre><code>zipOutStream.close(); </code></pre> <p>Once the zip file is created you'll still need to return that to the user.</p> <p>Edit: One option is to create the zip file output stream wrapping the response output stream. That way the zip file doesn't need to be stored on the server either. I haven't tested this option though.</p> <pre><code>zipOutStream = new ZipOutputStream(response.getOutputStream()) </code></pre> <p>We do the zip file building on a separate machine which has its own Tomcat server to return the zip file. The user is presented with a "wait" page showing a list of the files they selected which automatically refreshes to show the link to the zip file once all the files are zipped. This way the user can rethink the download once they see the size of the zip file. It also keeps the zip files off the main application server.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload