Dear community,
I am stuck with a Button that downloads dynamic context (PDF files) and would appreciate your help:
public class DownloadStreamButton extends Anchor {
public DownloadStreamButton(String buttonText, String filename, Supplier<byte[]> bytes) {
super(new StreamResource(filename, () -> new ByteArrayInputStream(bytes.get())), "");
Button button = new Button(buttonText, VaadinIcon.CLOUD_DOWNLOAD.create());
button.addThemeVariants(ButtonVariant.LUMO_SMALL);
getElement().setAttribute("download", true);
getElement().appendChild(button.getElement());
}
}
The StreamResource accepts a Supplier for the data but not for the filename.
Any advice? Thank you!