There is also an excellent JGuru FAQ on this topic here -
http://www.jguru.com/jguru/faq/view.jsp?EID=160.
Tom
-----Original Message-----
From: Vyacheslav Pedak [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 13, 2000 4:54 AM
To: [EMAIL PROTECTED]
Subject: Re: File upload to database
See Jason Hunters site http://www.servlets.com/
He wrote a package com.oreilly.servlet and
there is a MultipartRequest class
http://www.servlets.com/resources/com.oreilly.servlet/MultipartRequest.html
which can help you.
It work fine for me.
Vyacheslav Pedak
----- Original Message -----
From: Kiran <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, April 13, 2000 2:31 PM
Subject: Re: File upload to database
> 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.
>
___________________________________________________________________________
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