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

File Upload Servlet

Ryan Lowe

Joined: Aug 04, 2003
Posts: 18
I am trying to upload a file via an HTTP <INPUT TYPE="FILE" NAME="file_part"> parameter using Servlets. I have downloaded the O'reilly packages, and gotten them to work ... but I am having trouble writing my own (learn by doing ). I have tried:
File f = new File ( request.getParameter ( "file_part" ) ); (which throws a NullPointerException, regardless of whether the field is populated).
AND too many hours of fruitless labor. Any suggestions? I can manipulate files fine, but I just can't GET the file
Ryan Lowe
Malhar Barai
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Plz do a search on this forum on "file upload", go through the results, your problem would be solved by that.
Torsten Schippel
Ranch Hand

Joined: May 09, 2003
Posts: 62
Hi Ryan,
try a BufferedReader to read the lines posted by your form.

You should find the difference between a normal form POST and an "multipart/form-data" POST.
Then you may be able to write your own multipart parser.
Ryan Lowe

Joined: Aug 04, 2003
Posts: 18
Thank you Torsten. That provided me with the direction I needed Also, Malhar ... Most of the references on JavaRanch point to the oreilly packages or other libraries, not instructions on how to do it *manually*.
Thanks Again,
I agree. Here's the link:
subject: File Upload Servlet
It's not a secret anymore!