I have a PDF file on my server that I need the user to download from the client side.
Using Spring Framework, I use javax.servlet.http.HttpServletResponse to create the correct response and corresponding header:
response.setHeader("Expires", "-1");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment;filename="content.pdf");
response.setContentLength(content.size());
Then I use the ServletOutputStream to write the content:
ServletOutputStream os;
try {
os = response.getOutputStream();
os.write(((ByteArrayOutputStream)baos).toByteArray());
baos.close();
os.flush();
os.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
On the client side, I receive HTTP code 200 and receive the correct response body, with the PDF file, but the 'Save As...' pop-up did not appear.
Is there any reason on the Header configuration that could lead to this problem or could it be somewhere else?
Thank you.