Team,
I am not able to download PDF file consistantly from IE8 while in mozilla it is working fine. We are setting Content-Length header and it is coming same for success ful and corrupted download.
When we use 'open' option from IE it fails 1 out of 5 time (failing one is also having proper content length). 'save' option is always working consistantly
Given below is code snippt we tried.
File f = new File("/opt/temp/test.pdf");
InputStream inputStream = null;
try
{
resp.setHeader("Pragma", "public");
resp.setHeader("Content-Transfer-Encoding", "binary");
resp.setHeader("Cache-Control" , "must-revalidate, post-check=0, pre-check=0");
resp.setHeader("Content-Description", "File Transfer");
resp.setHeader("Expires", "0");
resp.setHeader("Content-Length",String.valueOf((int)f.length()));
resp.setContentLength((int)f.length());
os=resp.getOutputStream();
inputStream = new FileInputStream(f);
byte[] data = new byte[(int)f.length()];
inputStream.read(data, 0, (int)f.length());
// Write the response to
Servlet output stream
os.write(data);
}
catch (Exception ex)
{
e.printStackTrace();
}
finally
{
try {
if (os != null) {
os.flush();
os.close();
}
if(inputStream != null)
{
inputStream.close();
}
if (f != null)
{
//
boolean deleted = f.delete();
if(!deleted)
{
f.delete();
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}