aspose file tools*
The moose likes Servlets and the fly likes without creating ZIP file on server (hard disk) and give it to client (download) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "without creating ZIP file on server (hard disk) and give it to client (download)" Watch "without creating ZIP file on server (hard disk) and give it to client (download)" New topic
Author

without creating ZIP file on server (hard disk) and give it to client (download)

saipraneeth nallapareddy
Ranch Hand

Joined: Dec 02, 2009
Posts: 159
hello everyone,

I am having a requirement in which i will let users choose a list of files (using check box) and let him download all the files he selected to download by zipping them and show him the download prompt for Open/Save/Cancel.

I am able to do this by creating the zip file on the server hard disk and making use of this file and let the user to download the files, every thing is going fine. But i don't want to create a zip file on the harddisk, i want to create it on the fly and let user download the zip file, at any point of time there should be no .zip file on my server.

can anyone suggest me how to achieve this, can anyone help me in this regard.
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

Depending on how large the files are, this may not be a good idea. If the files are megabytes in size, for example, then this will take up a lot of memory and may negatively impact the overall performance of your web application. But if you don't think that this will be a problem, you should be able to accomplish this by passing a ByteArrayOutputStream into the constructor of the output stream object.


SCJP 6 || SCWCD 5
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Simply stream the zip file to the response's output stream. Start like this:

Then write to the ZipOutputStream the same way you are doing it now. Don't forget to close it when you're finished.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: without creating ZIP file on server (hard disk) and give it to client (download)