Hi Vyacheslav,
Thanks a lot for the tip. But right now i am unable to even upload a file to
the server file system. If you have had expereince with something similar i
would appreciate if you could please give me a tip on how to retrieve the file
content from the request object.
Here is what i am trying.
BufferedReader InFile = new BufferedReader(new
InputStreamReader(req.getInputStream()));
try{
String s = "";
StringBuffer sb = new StringBuffer();
int size = req.getContentLength();
int to_read = (size > 4096) ? 4096 : size;
int bytes_read = 0;
char[] b = new char[4096];
for (int i = 0; i < size; i++) {
bytes_read = InFile.read(b, 0, to_read);
if (bytes_read == -1) {
break;
}
i += bytes_read;
to_read = ((size - i) > 4096) ? 4096 : (size - i);
s = new String(b);
sb.append(s.substring(0, bytes_read));
}
show(" sb = " + sb.toString());
The vaue of sb is printed as:
sb = f_name=abc&name=def&filename=C%3A%5Ccupofjava%5Cmails2000%5Ctest1.htm
The file i am trying to upload is: C:\cupofjava\mails2000\test1.htm
How do you retrieve the file contents from the request object after getting the
filename.
Also what is the content type that is required to be set in the HTML form while
posting the data to the servlet.
I am aware of file streams:
FileOutputStream fos;
fos = new FileOutputStream(filename);
OutputStreamWriter osw = new OutputStreamWriter( fos );
Writer OutFile = new BufferedWriter( osw );
OutFile.write( FileData );
OutFile.close();
How do you separate the file content from the request object?
Any tips/suggestions will be appreciated.
TIA.
Bye.
-Kiran.
Vyacheslav Pedak wrote:
> First of all you should specify mime type of your file by
> response.setContentType, for example "application/pdf"
> for pdf files.
> Also it will be useful to specify file name by
> res.setHeader("Content-disposition", "attachment;filename="+filename);
> Then you read your file from database by
> resultset.getBinaryStream and output it to client
> by sending it to OutputStream (response.getOutputStream)
>
> Vyacheslav Pedak
>
> ----- Original Message -----
> From: Kiran <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, April 13, 2000 10:49 AM
> Subject: File upload to database
>
> > Hi Everyone,
> > I am trying to upload a binary (.pdf, .doc, .gif etc) file to the
> > oracle8i database table ( BLOB column). It is also required to download
> > the file to the client machine from the database on request (HTML
> > client). I searched the archives but was unable to find anything similar
> > (wrt database). I would really appreciate if any of you could please
> > give me tips/links on how to do the same.
> > Thanks much.
> > -Kiran.
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Talk to your friends online with Yahoo! Messenger.
> > http://im.yahoo.com
> >
> >
> ___________________________________________________________________________
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> > of the message "signoff SERVLET-INTEREST".
> >
> > Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > Resources: http://java.sun.com/products/servlet/external-resources.html
> > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
> >
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html