I do it like this and it works fine also for large files (50mb pdf, didnt
try above yet). Same way to write it but u might need the MIME, Header and I
use ServletOutputStream not Buffered one.
Document doc = (Document) s.getObject(s.createObjectId(objectid));
String filename = doc.getName();
String MIME = doc.getContentStreamMimeType();
InputStream in = doc.getContentStream().getStream();
response.setContentType(MIME);
response.setHeader("Content-Disposition","attachment;filename=\"" +
filename + "\"");
ServletOutputStream out = response.getOutputStream();
byte[] outputByte = new byte[in.available()];
int sizeRead = 0;
while((sizeRead = in.read(outputByte, 0 , outputByte.length)) > 0) {
out.write(outputByte, 0 , sizeRead);
}
in.close();
out.flush();
out.close();
all the best
Sebastian
2011/6/4 Naresh Bhatia <[email protected]>
> I would like to return the content of a document in a HttpServletResponse.
> What I have right now is shown below. Is there a better way? Will this
> scale
> for large video content?
>
> InputStream src = new BufferedInputStream(
> document.getContentStream().getStream());
>
> BufferedOutputStream dst = new BufferedOutputStream(
> response.getOutputStream());
>
> byte[] buff = new byte[2048];
> int bytesRead;
> while((bytesRead = src.read(buff, 0, buff.length)) != -1) {
> dst.write(buff, 0, bytesRead);
> }
>
>
> Thanks.
> Naresh
>