Vaadin 7 Alpha 3 Download zip file

Simple requirement… how to download a zip file as the result of button click or panel click.
After hours and hours of searching and trying suggestions for file download in the forum and elsewhere, many suggestions offer only partial and in my case, ideas that do not seem to work.
Can someone offer a working suggestion (Alpha 3 nightly) to achieve this task for downloading a file(for example kept in the VAADIN/files directory)?
If page.open(resource) is the answer, how is it coded?
The fact that there have been so many forum topics on this subject seems to indicate that some clarity is needed.

regards
Paul Fraser

As usual, post a request and you find the answer faster!

Call doDownload in the click handler for a panel or button…works for me :bashful:

  private void doDownload(String downloadFileName) {
    String basepath = getApplication().getContext().getBaseDirectory().getAbsolutePath();
    String downloadFilePath = basepath + "/VAADIN/files/" + downloadFileName;

    FileResource fileResource = new FileResource(new File(downloadFilePath), getApplication());
    Page.getCurrent().open(fileResource);
  }

Paul

Just a small warning: That approach causes some additional file download warnings in most browsers and e.g. IE8 will reload the page after you accept the download, which might harm the user experience.

The suggested way is to instead create a Link pointing to the FileResource. In that way, the download will be started as a direct reaction to the user’s action (as opposed to a reaction to something that was received from the server), which makes the browser less cautious.

Thanks, Leif,

Can a link be used with a button or panel click somehow, or does a link have to be made to look like a button or panel using a theme?
Actually I wanted to do download by clicking an image (in a panel).

Paul

If you want to start the download when by clicking an image, you can use a Link with empty caption and the image set as the Link’s icon.

Perfect, just what I need.

Thanks Again Leif,

Paul