File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes FIle Upload from Client to Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "FIle Upload from Client to Server" Watch "FIle Upload from Client to Server" New topic

FIle Upload from Client to Server

Nair Anoop
Ranch Hand

Joined: May 09, 2001
Posts: 68
Hi All,
I have written a small EJB and JSP which uploads some user info from a form to the DB. I would also like to upload a file from the user to the server.
Any ideas / resources on how this can be done ?
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

In my company this is known as "the file upload problem".

To perform file uploads, you use a different type of form encoding (offhand it's called multipart/form-data). This means that the handy request.getParameter("xxx"); won't work!

Also problematic is the habit of some app servers (namely iPlanet!) to attempt to parse this kind of form data into name value pairs, and failing, to throw the data away.

However, if you use a 'normal' server (one that isn't buggy in this respect), I'd suggest using the oreilly classes.
Sergei Voropay
Ranch Hand

Joined: Feb 20, 2001
Posts: 31
Instead of writing all the code to deal with multipart form data you probably better off using prebuilt components available from different vendors. Some application servers supply their own classes/components designed specifically for that purpose (i.e. Orion supplies FilePostParser and PostFileInputStream to work with multipart data). You could also use either classes available from o'reilly or a tag-lib from (jspSmartUpload).
I agree. Here's the link:
subject: FIle Upload from Client to Server
Similar Threads
how can i read local file from server side?
Image file upload without selecting file from local file system
Creating File object problem
Uploading and using a file from a web page
finding mimetype using javascript