Download file or zip file in Vaadin Flow

Am struggling with getting the download of file to work. My requirement is I could have a xlsx or csv or zip file that could be sent from server which needs to be downloaded. Although I preferred an automatic download, trying to at least get the button click to achieve that, and struggling. Any help will be most appreciated.

Two problems am facing in the following code snippet:
a. In the click listener, the first block process, although has no errors, and seems to construct the href just fine, doesn’t download the file on button click, whereas the second block does for xlsx file at least.

b. The method that generates the StreamResource - I don’t know how to make it compatible to also stream Zip file. And these zip files could be humongous ones, so looking for the most efficient method.

I have looked at FileDownloadWrapper and I think that won’t be a feasible option.


public class MainView extends SplitLayout{
	private Anchor download;
	private Button downloadButton = new Button("Download");
	public MainView() {
		HoizontalLayout buttons = new HorizontalLayout(downloadButton);
		download = new Anchor();
		download.getElement.setAttribute("download", "true");
		downloadButton.addClickListener(e -> {
                           //this block doesn't download,
                           File file = new File(resultFileName);        
                           resource = getStreamResource(resultFileName, file);
                           System.out.println("resource = " + resource.getName());
                           System.out.println("href set : " + download.getHref());
						   //this block does the trick
						   final StreamRegistration regn = VaadinSession.getCurrent().getResourceRegistry().registerResource(resource);
	//This is able to only Stream regular file, and not zip file
	public static StreamResource getStreamResource(String fileName, File file) {
             return new StreamResource(fileName, () -> {
                                 try {
                                        return new FileInputStream(file);
                                 } catch (IOException e) {
                                        System.out.println("Error in getStreamResource: ");
                                 return null;