Grails Programmer: How to output CSV from a Grails 3 Controller. 20 / 1 Reply def outs = Stream. = (). response. Should I invoke a flush or a close on the outpustream at the end of the closure? () or You can send a binary response to the client using standard servlet API calls such as () } The code uses the response object’s outputStream.
|Published (Last):||6 May 2009|
|PDF File Size:||5.89 Mb|
|ePub File Size:||19.12 Mb|
|Price:||Free* [*Free Regsitration Required]|
Proper way to stream file from controller.
Grails Programmer : How to output CSV from a Grails 3 Controller
On Wed, Jul 30, at 1: I should add that I had tried a similar approach following another StackExchange post maybe yours? GrailsConfigurationAware import static org. The first file is just a plain text file: The output of the finished application will look like this: I will then get an Reponse.outputstream Generally things are working but today we ran across a problem that seems to be shared by others but I cannot find a solution.
Lauk To unsubscribe from this list, please visit: The code now appears as response. Then we use the render method and the file and contenType attributes to render the image in a browser: I have a Grails application that I have recently upgraded to 3.
This will also set a response header with the name Content-Disposition with a the filename as value. I believe I’ve read somewhere that I might be able to cure this problem by replacing Tomcat7 with Tomcat8; however right now I’m running Ubuntu The zip file contains two files: CSV is probably the best format to export your data from a Grails App.
If the byte arrays in your examples are large, or if the ‘download’ action is called frequently, you could run into problems. If that’s the case, copy from stream to stream. We have fixed this problem in our applications by adding a static utility method: Should I invoke a flush or a close on the outpustream at the end of the closure?
Your email address will not be published. A weekly curated email newsletter about the Groovy ecosystem.
C If you want the file to download you need to setup the Content-disposition header. Daniel 1, 1 3 Notify me of follow-up comments by email.
Grails User (Old Archive) – Proper way to stream file from controller
A simple page with download link vrails shown: Thanks If you are using Grails 2, just change the setConfiguration part to this: I wrote a post; in Spanish though. The file attribute can be assigned a byteFileInputStream or String value. I also typed the methods as void perhaps I am still too Java-fussy? Based from this, it is easy to modify the sample to put different types of files inside the output ZIP.
Hi all, I have a controller which would stream file as response. In a controller I have a method that appends a string to the response.