Before writing data, you must set the Content-Length
header, or the server is forced to buffer all the data until the stream is closed, and at this point it can calculate the value itself, write the header and send all the data. Once you get the output stream, before writing any data, set the content length:
response.setHeader("Content-Length", String.valueOf(blob.length()));
Most servers are smart enough to flush the buffer itself at this point, so you probably don't even need to call flushBuffer()
, although that doesn't hurt.
source share