Download dynamically generated text file

Hi.

On server side I generate dynamic text file (from database, kind of a report).

I would like to put a “download” link on a form. User would click on link, and download generated file. I wouldn’t like to save file on disk or something like that, I would rather use on-the-fly stream.

any ideas?

bye,ivan

You use a URIHandler to provide dynamically generated content for download. See
the Resources chapter
in Book of Vaadin for more info.

Thanks.

I ended up with ResourceStream, which in turn goes to SourceStream when link is clicked on. SourceStream invokes callback method that returns array of bytes.

So i had the same problem. I generated a file Dynamically on the Server and wanted to download in a new Window.

I got it worked with following hack :wink:

                var resurce = new StreamResource("somePdf" + ".pdf", () -> new ByteArrayInputStream(somebyteArray));
                btnRef.getElement().setAttribute("data", resurce);
                var attrUrl = btnRef.getElement().getAttribute("data");
                UI.getCurrent().getPage().open(attrUrl);