Implement a download functionality using a button renderer

I’m trying to implement a download functionality using a button renderer within a Grid, but I don’t know how to make it work. Here is a part of my code:

@Override
public void click(RendererClickEvent event)
{
final javax.xml.transform.stream.StreamSource source = new javax.xml.transform.stream.StreamSource(image_byte);
final StreamSource streamSource = new StreamSource()
{
@Override
public InputStream getStream()
{
return source.getInputStream();
}
};
StreamResource streamResource = new StreamResource(streamSource, nome_arquivo);
FileDownloader fileDownloader = new FileDownloader(streamResource);
fileDownloader.extend(event…);
}

I played around this subject a bit last spring and came up with
GridFileDownloader add-on
, but it’s not exactly perfect and I haven’t had time to work on it since. You might find some inspiration from the sources, though.

Did you try “DownloadStream” ?

final FileResource stream = new FileResource(new File(“”)) {
@Override
public DownloadStream getStream() {
DownloadStream ds = null;

            // String filename = do sth;
            //some operation for ByteArrayInputStream
            //ByteArrayInputStream in = new ByteArrayInputStream(anyVal);
            //ds = new DownloadStream(in, "application/xml", filename);
            // Need a file download POPUP
            //ds.setParameter("Content-Disposition", "attachment; filename=" + filename);

            return ds;
        }
    };
    UI.get().getPage().open(stream, stream.getFilename(), true);