Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Appengine JAVA - Zip lots of images saving in Blobstore
    text
    copied!<p>I developed a simple media library where you can choose a set of images and download them. When a client request a download, a servlet receives the blob keys to use for create a zip file and then a Task is launched for the procedure</p> <p>The task iterate through the received blob keys and zip the images into the archive. When the task has finished a mail with the download link is sent to the user.</p> <p>Here is my problem:</p> <pre><code>FileWriteChannel writeChannel = fileService.openWriteChannel(file, lock); OutputStream blobOutputStream = Channels.newOutputStream(writeChannel); ZipOutputStream zip = new ZipOutputStream(blobOutputStream); </code></pre> <p>A single channel can handle only this amount of bytes</p> <blockquote> <p>BlobstoreService.MAX_BLOB_FETCH_SIZE</p> </blockquote> <p>Because of that, i must open and close the channel every 1mb of data i have to write (same issue for the read, but for the read i used <a href="https://stackoverflow.com/a/11105235">this code</a> and it works). or the write() method throws a null exception</p> <p>Opening and closing the channel with a normal outputStream, does not presents issue, like <a href="http://jsfiddle.net/fDrYt/" rel="nofollow noreferrer">this code</a></p> <p>But handling a Zip file i also have to manage</p> <pre><code>ZipOutputStream zip = new ZipOutputStream(blobOutputStream); ZipEntry zipEntry = new ZipEntry(image_file_name); zipOut.putNextEntry(zipEntry); // while the image has bytes to write zipOut.write(bytesToWrite); </code></pre> <p>After i wrote 1MB of data in the ZipEntry i have to close the channel and open it again.</p> <p>So here the problem: where i open a new channel i can't access to the previouse zipEntry i was writing and then i cannot continue to write the next 1MB of the image i'm processing. </p> <p>And, after a open a new channel, if i try to write on the zipEntry object (w/o re-initializing it) i get a ClosedChannel exception</p> <p><a href="http://jsfiddle.net/97r2W/" rel="nofollow noreferrer">Here</a> is the SAMPLE code i wrote, i know is not working, but explains what i am trying to do.</p> <p>My question then: How (if is possible, off course) can i create a zip file writing 1MB per time?</p> <p>I'm also available to other approaches, the thing i need is to zip some images into one zip and save it into the blobstore, if you have other ideas to make this, please tell me</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