RE: downloading files with a servlet
"Edward W. Rouse" <[email protected]> Wed, 19 Jul 2006 14:20:30 -0400
| Newsgroups | gmane.text.xml.resin.user |
|---|---|
| Message-ID | <[email protected]> |
out.flush(); Edward W. Rouse ComSquared Systems, Inc. 770-734-5301 > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of dlevy > (sent by Nabble.com) > Sent: Wednesday, July 19, 2006 1:33 PM > To: [email protected] > Subject: downloading files with a servlet > > > > 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-tf19677 49.html#a5400786 Sent from the Resin forum at Nabble.com.