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 GRAILS IllegalStateException error for return the Stream # Closed. graemerocher opened this Issue on Oct 29, · 0 comments.
|Published (Last):||1 January 2010|
|PDF File Size:||15.18 Mb|
|ePub File Size:||12.69 Mb|
|Price:||Free* [*Free Regsitration Required]|
On Wed, Jul 30, at 9: I should add that I had tried a similar approach following another StackExchange post maybe yours?
Grails Programmer : How to output CSV from a Grails 3 Controller | Sergio del Amo
Use TAB for completion: If we run the app and call the controller we will download a CSV file as this: Hi all, I have a controller which would stream file as response. Handler dispatch failed; nested exception is java. The BootStrap init closure runs when the app starts. This will also set a response header with the name Content-Disposition with a trails filename as value. Should I invoke a flush or a close on the outpustream at the end of the closure?
Search everywhere only in this topic. This is nice and clean and works just fine. I was tired of my clients asking me how to import a CSV in Excel.
Since Grails 2 we can render binary output with the render method and the file attribute. Render Binary Output with the File Attribute. Does anyone have any suggestions for me? B I am using the mime type and encoding defined in application.
I have a Grails application that I have recently upgraded to 3. Learn more about retrieving config values. Will give this a shot. The file attribute can be assigned a byteFileInputStream or String value. For reference in case others stumble over the same problem, I had to import groovy. Proper way to stream file from controller.
Proper way to stream file from controller
We have fixed this problem in our applications by adding a static utility method: Your email address will not be published. Thanks Garils you are using Grails 2, just change the setConfiguration part to this: My code is only a little different, in that I don’t set the “Content-disposition” header and flush afterwards.
A I will recommend to put the logic fetching the lines in a Service.