This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes File Upload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "File Upload " Watch "File Upload " New topic

File Upload

Tano Ortiga

Joined: Jan 03, 2001
Posts: 9
Hi Guys,
I want my webserver to have "file upload" capabilities. Can I use Tomcat webserver in this case? Also, i don't know how to retrieve the attached file/s from client to the server (servlet). can anyone help me on this? pls provide code snippets if possible. thanks.
Tano Ortiga

Joined: Jan 03, 2001
Posts: 9
Additional Questions:
how do i "store" the file into an object/variable?
how do i "store" the file into a database ?
thanks again.
Satish Kasala

Joined: Dec 19, 2000
Posts: 16
here's code for file upload.
<form ENCTYPE="multipart/form-data" action="/servlet/FileUpLoad" method="POST">
<input name='upfile' type='file'>
<input type="submit" name="Upload" value="Transfer the file">
int iTotalBytes = this.oRequest.getContentLength();
BufferedReader oInFileData= new BufferedReader(
new InputStreamReader(this.oRequest.getInputStream()));
char[] arData = new char[iTotalBytes];;
arData contains the contents of the file as well as some more information regarding
the request. you can filter out what you need from the array.
Hope this helps
Danny Mui
Ranch Hand

Joined: Dec 14, 2000
Posts: 42
You can also obtain the O'reilly multi-part request handler (which parses an enctype of multipart that file-uploading requires). You can find the library at
Tano Ortiga

Joined: Jan 03, 2001
Posts: 9
thanks guys!

Joined: Jul 12, 2001
Posts: 3
Now,there is a html file in client.
But i ave a question,
if they are both java source code in client/Server.
How to code in client??
It is sorta covered in the JavaRanch Style Guide.
subject: File Upload
Similar Threads
File Upload in webserver and appserver
Upload files gives an OutOfMemoryError
File upload to a different url than hosting server
How to upload a file on webserver using midlet and servlet
uploading file