I am using wicket framework, and I have made a zip file by Java code, I want to have a link to download it, I don't know if it is possible or I should make the zip file by wicket (but not Java) and then have a link to download.
Asked
Active
Viewed 4,863 times
1 Answers
7
Take a look at ZipResourceStream
. With this class you can generate zip contents of a directory on the fly, and use a org.apache.wicket.markup.html.link.ResourceLink
with ResourceStreamResource
to link to 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 zip 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 the Link's onClick, take a look at this question: How to use Wicket's DownloadLink with a file generated on the fly?

Community
- 1
- 1

Xavi López
- 27,550
- 11
- 97
- 161