I have a filename, mimeType and data in byte and want a Button where the user can download this dynamically created file.
Until Vaadin 8 there has been e.g. FileDownloader [1]
.
In Vaadin 10 (Flow/Java) I can create a StreamResource [2]
but I don’t find the way how to trigger the download.
Any help or example is welcome.
thanks for the hint to ‘Anchor’, example and link to the old post which I really didn’t find.
But … what I want to achieve is that I have a Button and only on click several things shall be done which result in the bytes which should be offered as download.
So using anchor would allow me to have the Button-click and than open a new dialog where the Anchor to the download could be offered.
Is there any solution where a Button clickListener can trigger first internal calculation and than offer a resulting download without an additional Dialog? That would be great.
I’m not sure if I understand your need correctly.
You want a button and when you click on it you can generate your file (dynamically) and download it ?
In that case you can:
Use this anchor and add class=“button” (with some CSS :p) and the anchor looks like a button.
When click on my anchor, file is generated (the streamresource is built when you click on the anchor) and downloaded.
I don’t know if you can use directly a button (I did that on vaadin 10 beta so I didn’t look for other solution).