Jsp download file size

We start tomcat and we create PDFs on the fly. I don't have the file size in front of my hand, so I cannot directly link to the file on the server. So I am sending the output directly.

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

      

And then I directly output to that OutputStream.

The only problem is that the recipient doesn't get the file size, so they don't know how long the download will take. Is there a way to tell the answer how big the file is?

EDIT I know the size of the file, I just can't tell STREAM how big the file is.

0


source to share


4 answers


The response object must have a setContentLength method :



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

      

+5


source


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



+1


source


I believe you are listening to yourself to yourself: Quote: I don't have the file size before uploading, so I'm sending the output directly.

If you don't have a size, you cannot send it ....

0


source


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

response.setContentType ("app / push download"); response.setContentLength (sizeHere); OutputStream o = response.getOutputStream ();

0


source







All Articles