In my Grails controller I have an image as byte []. I want to write this byte [] directly to the response.outputStream
I use the following code to do that:
Grails don't know that you've already processed response, and if you aren't returning anything grails tries to apply default logic.
Put
return null
at the end of your action.
The error you are showing has to do with at what point the code you posted gets executed. The exception says
java.lang.IllegalStateException: Cannot forward after response has been committed
An HttpServletResponse
is typically committed, ie. the headers are sent, when you start writing to its OutputStream
. At this point you cannot change the headers or status code and you cannot use a RequestDispatcher
to forward()
the request to another resource.
Check if you are doing any of these things.