Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download a file using GWT client?

Tags:

java

servlets

gwt

What is the best way to download a pdf file using GWT client ? Should I invoke a normal servlet to do that ? or is there a different preferred approach to handle this problem ?

I am new to GWT, so if some sample code would be of great help.

Thanks Deep

like image 220
DG. Avatar asked Oct 26 '10 05:10

DG.


2 Answers

Try it with GET...

Window.open(GWT.getHostPageBaseURL() + "FileRepository/doDownload?docId=" + dokument.getId(), "", "");
like image 177
cupakob Avatar answered Nov 14 '22 17:11

cupakob


You can implement a Servlet download the file OR you can do that using Data URIs:

  1. Make your GWT RPC method return the file content or the data to generate the file.
  2. On the client side, format a Data URI with the file content received or generate the data content.
  3. Use Window.open to open a file save dialog passing the formatted DataURI.

Take a look at this reference, to understand the Data URI usage:

Export to csv in jQuery

like image 20
Italo Borssatto Avatar answered Nov 14 '22 16:11

Italo Borssatto