Mail Archive Home | enhydra List | May 2004 Index
| <-- Date Index --> | <-- Thread Index --> |
Hi,
you can do that without saving document to file.
First you have to read document from database( as I understand that is
not problem for you ).
Than you have to set MIME type for content type to http response - if Your
server is
Enhydra you could do that with : comms.response.setContentType(type);
where type is MIME type that you need - if you want to send .doc file(
MSWORD file) than MIME type should be : 'application/msword'.
-e.g
comms.response.setContentType("application/msword");
You can set additional informations about content, file name for
example - to do this set Header named "Content-Disposition"
-e.g
comms.response.setHeader("Content-Disposition",
"inline; filename=\"" + NAME_OF_THE_FILE + "\"");
Next step is to read document bytes and send it to client.
First, get input stream from your document ( if you using BLOB,
you can use Blob.getInputStream() method ) to read document's bytes.
After that you have to send document's bytes to response output stream.
Get output stream from response chanel and write document's bytes to it.
Below is example peace of code that you can use.
InputStream inputStream = blob.getBinaryStream();
byte[] buffer = new byte[4096];
BufferedOutputStream bu = new
BufferedOutputStream(comms.response.getOutputStream());
int no = inputStream.read(buffer);
while (no > -1) {
bu.write(buffer, 0, no);
no = fi.read(buffer);
}
bu.flush();
comms.response.flush();
When you send bytes to client this way, than you
don't need to use comms.response.writeDOM() or some other method to
make response from server to client.
Best regards,
Zoran
Sunday, May 30, 2004, 2:15:21 AM, you wrote:
byc> Hi! I'm trying to get an image data (.doc) from sql server and show it
in a browser. I could save it to a file and then reference it, but for me it
doesn't make sense because then, what is the
byc> reason for saving it into the database. If anybody could help me, I'll
preciate it, my thesis depends on that.
| <-- Date Index --> | <-- Thread Index --> |
Powered by MHonArc.
Copyright © 1999-2005, ObjectWeb Consortium | contact | webmaster.