The following action is meant to write the binary content of bytes
directly to the client completely bypassing the Grails view layer:
def actionName = {
byte[] bytes = ...
ServletOutputStream out = response.getOutputStream()
out.write(bytes)
out.flush()
out.close()
return false
}
I was under the impression that return false
would make Grails completely skip the view layer. However, that appears not to be the case since the above code still makes Grails search for /WEB-INF/grails-app/views/controllerName/actionName.jsp
(which fails with a 404, since no such file exists).
Question:
You should return null or nothing at all, which is interpreted as null. Here's some working code from an action that sends a dynamically generated PDF:
def pdf = {
byte[] content = ...
String filename = ...
response.contentType = 'application/octet-stream'
response.setHeader 'Content-disposition', "attachment; filename=\"$filename\""
response.outputStream << content
response.outputStream.flush()
}
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