Question

We are running tomcat, and we are generating pdf files on the fly. I do not have the file size before hand, so I cannot direcly link to a file on the server. So I directly send the output.

response.setContentType("application/force-download");
OutputStream o = response.getOutputStream();

And then I directly output to this OutputStream.

The only problem is that the receiver does not get the filesize, so they do not know how long the download will take. Is there a way to tell the response how large the file is?

EDIT I do know the filesize, I just cant tell the STREAM how big the file is.

Was it helpful?

Solution

The response object should have a setContentLength method:

// Assumes response is a ServletResponse
response.setContentLength(sizeHere);

OTHER TIPS

Serialize the PDF byte stream to a file or in a byte array calculate its size, set the size and write it to the output stream.

I beleive you're ansering the qustion your self: quote: I do not have the file size before hand, so I directly send the output.

If you don't have the size you cant send it....

Why not generate the PDF file in to temp file system , or ram-base file system or memory-map file on the fly. then you can get the file size.

response.setContentType("application/force-download"); response.setContentLength(sizeHere); OutputStream o = response.getOutputStream();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top