Hello,
I am trying to download a file (say c:/test) from the server to client.
Now it shows the content of the file inside the panel.
But I would like it to show the browser “save/open” window so that the user can choose to save it.
I saw a few posts about it, but did not really find the solution that works.
By the way, it works fine on firefox, but not on explorer.
What am I missing here?
Any help would be appreciated.
Panel myPanel = new Panel("my panel");
Embedded embedded = new Embedded();
FileResource fResource = new FileResource(new File("C:/test"), getApplication());
embedded.setSource(fResource);
fResource.getStream().setParameter("Content-Disposition", "attachment; filename=" + "test");
//embedded.setMimeType("application/octet-stream");
embedded.setType(Embedded.TYPE_BROWSER);
myPanel.addComponent(embedded);
I actually found the solution right after I posted the question.
I got it from an earlier post, for some reason it did nto work before.
I had to extend the FileResourse as below:
I have noticed that Google Chrome aggressively caches older copies of files when I use the above FileDownloadResource sample, and then open the file from the main window as follows:
FileDownloadResource downloadResource = new FileDownloadResource(
new File(filePathName), getApplication());
event.getButton().getWindow().open(downloadResource, "_blank");
Is there a way to force it to refresh its cached copy every time? Firefox isn’t as bad about this. I want to make sure that the user does not get the old version of the file whenever I send it to the client this way.
Does anyone know of a way to force Chrome to update its cache with the new copy of the file each time open() is called? If not, is there another way to accomplish this? Thanks!