How to download a file from a server in Vaadin7?

I have a fileresource

FileResource curResource = new FileResource(new File(basepath + "/WEB-INF/docs/"+path+".pdf")); 

and I want to save this file from a browser on a computer by clicking a button. How can I do this in Vaadin 7? Thanks

I am trying something like this:

 ExternalResource resource = new ExternalResource(basepath + "/WEB-INF/icons/"+"block_16.png"); Page.getCurrent().open(resource.getURL(),"Download",true); 

but I'm empty: about a blank page and nothing happens ...

+6
source share
2 answers

I solve my problem!

 private String basepath = VaadinService.getCurrent() .getBaseDirectory().getAbsolutePath(); private Button saveExcel = new Button(); Resource res = new FileResource(new File(basepath + "/WEB-INF/docs/settings.xlsx")); FileDownloader fd = new FileDownloader(res); fd.extend(saveExcel); 

It is so easy to download from the server in Vaadin

+10
source

The problem with this solution is that: The file name and contents of the file must be known before you call fd.extend.

If you want to build the file name and file contents on demand, see the tutorial on the Vaadin wiki page: OnDemandFileDownloader: https://vaadin.com/wiki/-/wiki/Main/Letting%20the%20user%20download%20a% 20file

+8
source

All Articles