I'm using Play Framework 2.0.3 to create an application which delivers Excel files that should be downloadable by the user.
response().setContentType("application/x-download");
response().setHeader("Content-disposition","attachment; filename=tradeLogTest.xlsx");
but,how to get the outputstream from response()
?tks
Installation from the binary package In general, the installation instructions are as follows. Install Java. Download the latest Play binary package and extract the archive. Add the 'play' command to your system path and make sure it is executable.
To run the Play framework, you need JDK 6 or later. If you are using MacOS, Java is built-in. If you are using Linux, make sure to use either the Sun JDK or OpenJDK (and not gcj, which is the default Java command on many Linux distros). If you are using Windows, just download and install the latest JDK package.
Play's action can return a File:
response().setContentType("application/x-download");
response().setHeader("Content-disposition","attachment; filename=tradeLogTest.xlsx");
return ok(new File("/absolute/path/to/tradeLogTest.xlsx"));
Here's an API for Results
Providing download option for static files can be done in Play as:
Ok.sendFile(new File("path to file/abc.csv"), inline=true).withHeaders(CACHE_CONTROL->"max-age=3600",CONTENT_DISPOSITION->"attachment; filename=abc.csv", CONTENT_TYPE->"application/x-download");
There are other parameters that are also available
For Internet Explorer - make sure you set the Content Disposition
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