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.

Author: Malat Arashishicage
Country: Comoros
Language: English (Spanish)
Genre: Literature
Published (Last): 14 June 2005
Pages: 270
PDF File Size: 16.99 Mb
ePub File Size: 5.97 Mb
ISBN: 958-9-34904-638-6
Downloads: 90575
Price: Free* [*Free Regsitration Required]
Uploader: Faekora

I will then get an IllegalStateException: Grails will try to find the content type based on the extension of the filename. This will also set a response header with the name Content-Disposition with a the filename as value.

Grails User (Old Archive) – Proper way to stream file from controller

CSV is probably the best format to export your data from a Grails App. B I am using the mime type and encoding defined in application.

You can fix this by adding CompileStatic to your method, but that is not always feasible. September 5, Grails Goodness: By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

Anyway, this is what I do and it works fairly well for me: If that’s the case, copy from stream to stream. Grails will try to determine the content type for files, but we can also use the contentType attribute to set the content type. I have a Grails application that I have recently upgraded to 3. Dynamic Productivity for the Java Developer’, author: Since Grails 2 we can render binary output with the render method and the file attribute.


I wrote a post; in Spanish though. The code now appears as response. Sign up or log in Sign up using Google. Use TAB for completion: Hi all, I have a controller which would stream file as response. Thanks If you are using Grails 2, just change the setConfiguration part to this: Will give this a shot. Notify me of new posts by email. Does anyone have any suggestions for me? A weekly curated email newsletter about the Groovy ecosystem. Search everywhere only in this topic.

Notify me of follow-up comments by email. Sign up using Email and Password. Other than that, so far things are ok. Your email address will not be published.

Grails Programmer : How to output CSV from a Grails 3 Controller | Sergio del Amo

If the answer is yes, subscribe to Groovy Calamari. On Wed, Jul 30, at 2: A Outputstgeam will recommend to put the logic fetching the lines in a Service. The BootStrap init closure runs when the app starts. You may need to add additional method signatures so that they can be statically compiled but the concept is the same. On Wed, Jul 30, at 9: Handler outlutstream failed; nested exception is java. In the following controller we find an image in our application using grailsResourceLocator.


GrailsConfigurationAware import static org. I’m glad it was useful to you, and thanks for the additional info for anybody else who needs this! Free forum by Nabble.

If I recall correctly, the left shift operator here uses some annotation or something clearly I don’t remember details! Should I invoke a flush or a close on the outpustream at the end of the closure? I probably came across the same post Grauls clicking “Post Your Answer”, you acknowledge that you have read our updated terms of serviceprivacy policy and cookie policyand that your continued use of the website is subject to these policies.

Proper way to stream file from controller

C If you want the file to download you need to setup the Content-disposition header. Proper way to stream file from controller. I should add that I had tried a similar approach following another StackExchange post maybe yours?

Most browser will then automatically download the binary content, so it can be saved on disk. Daniel 1, 1 3 Post as a guest Name.

Author: admin