Download zip file

Hi everyone,

I have this code:

        downloadButton.addClickListener(event -> {
            byte[] zipFileData = createZipFile();
            if (zipFileData != null) {
                StreamResource streamResource = new StreamResource("", new InputStreamFactory() {
                    public InputStream createInputStream() {
                        return new ByteArrayInputStream(zipFileData);
                String requestUrl = UI.getCurrent().getPage().toString();
                String downloadUrl = requestUrl + "/download/";
                downloadButton.getElement().setAttribute("href", downloadUrl);
                downloadButton.getElement().setAttribute("download", "");

      "ZIP file downloaded");
            } else {
      "Error creating ZIP file");


At the end of process I get the notification "ZIP file downloaded", but I do not have no one zip to download. How can I solve? I use Vaadin 14.

I want it to start automatically

You need to have user interaction (like a click) in order to start a download

and I thought that what you were attempting to do with the click listener anyway?

The user interact with the download button, and I don’t want to use an anchor to save the .zip file on the local machine

You can place the button inside the Anchor

Just keep the anchor text empty

Thanks! it works :smile: