Download the zip file through the gates

I use the wicket framework and I made a zip file using Java code, I want to have a link to download it, I donโ€™t know if it is possible or I have to make a zip file by the gate (but not Java), and then download the link .

+4
source share
1 answer

Take a look at ZipResourceStream . With this class, you can generate zip-content of the directory on the fly and use org.apache.wicket.markup.html.link.ResourceLink with ResourceStreamResource to reference it.

 File file = new File(path); IResourceStream resStream = new ZipResourceStream(file); ResourceStreamResource resource = new ResourceStreamResource(resStream); ResourceLink link = new ResourceLink("link", resource); add(link); 

Alternatively, if you prefer to archive the file with another tool, you can use DownloadLink :

 File zipFile = generateZipFile(); IModel fileModel = new Model(zipFile); add(new DownloadLink("dllink", fileModel); 

If you prefer to generate the file on the fly in Link onClick, take a look at this question: How to use Wicket DownloadLink with a file created on the fly?

+7
source

All Articles