The difference between your implementation and mine is that I am not
setting the Cache-Control, Content-Disposition and Content-Length
headers. My download action seems to work fine in IE and Mozilla, but,
could you enlighten me on what I may be sacrificing?
Thanks,
Erik
Daniel Perry wrote:
Below is some code i wrote to do this. is some code i wrote:
Note the doc object is specific to my app it has methods for returning the
content type, filename, and a File object pointing to the document on disk.
I have used almost identicle code for outputting pdf data. I think you can
use "attachment" rather than "inline" to make the browser save the file
rather than view it.
Daniel.
// set response headers
response.setHeader("Cache-Control", "max-age=600");
response.setContentType(doc.getContentType());
//Send content to Browser
StringBuffer cd = new StringBuffer();
cd.append("inline");
cd.append("; filename=");
cd.append(doc.getFilename());
response.setHeader("Content-disposition", cd.toString());
response.setContentLength((int) doc.getFile().length());
// send data
ServletOutputStream sos;
sos = response.getOutputStream();
InputStream is = new BufferedInputStream(new
FileInputStream(doc.getFile()));
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
sos.write(buffer, 0, bytesRead);
}
sos.flush();
is.close();
// return null so it just outputs data (no forward!)
return null;
-----Original Message-----
From: Stefan Groschupf [mailto:[EMAIL PROTECTED]
Sent: 25 August 2004 14:46
To: Struts Users Mailing List
Subject: download binary content
Hi,
can someone point me to a resource that describe how to realize a
dowanload action?
Do I can write to the response object with out forwarding?
Thanks for any hints.
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]