Vaadin 8 has a FileDownloader component https://vaadin.com/docs/v8/framework/articles/LettingTheUserDownloadAFile.html
Is there something similar in v10?
Vaadin 8 has a FileDownloader component https://vaadin.com/docs/v8/framework/articles/LettingTheUserDownloadAFile.html
Is there something similar in v10?
You can get similar results at least with this snippet:
Anchor downloadLink = new Anchor(createResource(), "Download");
downloadLink.getElement().setAttribute("download", true);
(createResource being the same as in the above docs example)
Thanks Olli, I will give that a try.
Hi,
The Anchor solution above, works with static resources. However, I cannot find a way to generate the file to download dynamically the way we used to do in Vaadin 7 & 8. Is this still possible. Where can I find examples with Flow?
Anchor solution works for dynamic resource (see createResource method inside the linked documentation.
The resource is generated when user clicks on the anchor.
For example:
private void init() {
StreamResource resource = new StreamResource("export.xlsx",
this::createExport);
exportMonthUserButton.setHref(resource);
}
private InputStream createExport(){
return null;
}
Yes! There is.
With an Anchor component all you need is set it up without caption/text and add a button component. Example:
Anchor download = new Anchor(new StreamResource("filename.ext", () -> createResource()), "");
download.getElement().setAttribute("download", true);
download.add(new Button(new Icon(VaadinIcon.DOWNLOAD_ALT)));
Pay attetion that StreamResource is the com.vaadin.flow.server.StreamResource class.