In a Grails 2.1.1 controller I'm attempting to stream a video (mp4) file to the browser.
The following code works. However, since I'm not specifying a content type the browser will save the file directly.
OutputStream os = response.outputStream
ByteArrayInputStream is = new ByteArrayInputStream(videoInstance.data)
response.contentLength = videoInstance.data.length
os << is
If I try to change it to specify a content type...
OutputStream os = response.outputStream
ByteArrayInputStream is = new ByteArrayInputStream(videoInstance.data)
response.contentType = videoInstance.contentType
response.contentLength = videoInstance.data.length
os << is
...suddenly I get exceptions.
Software caused connection abort: socket write error. Stacktrace follows:
Message: Software caused connection abort: socket write error
and later
ERROR errors.GrailsExceptionResolver - IllegalStateException occurred when processing request: getOutputStream() has already been called for this response.
I've tried adding both a .os.flush() and os.close() to no avail. Any ideas what could cause this?