I am new to GWT and general web application.
I am making a GWT web application. One functionality it provides is to download file by clicking a button on the web page. Unfortunately, the file itself does not physically located on the server side. Server side needs to grab it through a REST call to another web service to get a InputStream of the file.
My question is that:
Many thanks
EDIT: I have found this example: How to use GWT when downloading Files with a Servlet?
In this example, the file is physically located on the server side. The file I got from the web service via a stream is very large and I don't want to save them on my GWT server side. Any suggestions?
We use a servlet like the example above. Just make sure you set the header and the file name to be of the appropriate type. (The filename must end in the proper ending)
// process the data (In your case go get it)
byte[] data = generateReturnBuffer();
// do not cache
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
// content length is needed for MSIE
response.setContentLength(data.length);
// set the filename and the type
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "attachment;filename=" + "fileName.pdf");
ServletOutputStream out = resp.getOutputStream();
out.write(data);
out.flush();
where the response is the servlet HttpServletResponse.
Look here for the valid mime types.
At some point you will need to store the data in either a file or in memory since certain versions of internet explorer require the file length.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With