downloading files with a servlet
"dlevy (sent by Nabble.com)" <[email protected]> Wed, 19 Jul 2006 10:32:36 -0700 (PDT)
| Newsgroups | gmane.text.xml.resin.user |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I have implemented a file upload/download function and everything works fine
except for the dowloading of PDF files. All other file types download fine.
With a pdf download, for some reason the file comes back unreadable with the
Adobe Reader exception: "There was an error opening the document. The file
is damaged and could not be repaired.".
This can be reproduced in Resin 2.1.7. Although with Tomcat, pdf files
download without a problem.
Has anyone had this problem?
Here is the java code:
BufferedInputStream fileInputStream = null;
OutputStream output = null;
BufferedOutputStream out = null;
File file = new File(fileToFetch);
getResponse().setContentType("application/x-download");
getResponse().setHeader("Content-Disposition", "attachment; filename=" +
displayFileName);
output = getResponse().getOutputStream();
FileInputStream tempStream = new FileInputStream(fileToFetch);
fileInputStream = new BufferedInputStream(tempStream,getBufferSize());
byte[] buffer = new byte[ getBufferSize()];
int bytesRead = 0;
out = new BufferedOutputStream(output, getBufferSize());
while((bytesRead=fileInputStream.read(buffer)) !=-1){
out.write(buffer,0,bytesRead);
}
--
View this message in context: http://www.nabble.com/downloading-files-with-a-servlet-tf1967749.html#a5400786
Sent from the Resin forum at Nabble.com.