Click to See Complete Forum and Search --> : Where's my uploaded file?


anw
10-28-2007, 09:16 PM
I am trying to upload a file, and the browser (a Firefox derivative called Iceweasel,distributed with Debian Linux) doesn't seem to be sending the file. The basic form is like this:

<form id="uploadform" action="/members/servlet/MapsAjaxSupport"
enctype="multipart/form-data" method="post">
<div class="fileinput">
<input id="pathfileup" type="file" />
<input id="upbut" type="submit" value="Upload" class="formbutton">
</div><!-- fileinput -->
</form>

When the request hits my servlet, I iterate through the pieces using the jakarta commons file upload, and never get a file, although I get everything else (added to the form with Javascript). Here is what I'm printing out from the request, using the header map & getting a reader on the request body:

**********
Request Header Values
Context Path= ''
Content Type= 'multipart/form-data; boundary=---------------------------81707749216045394012024245416'

Header Name/Values
Oct 28 20:50:05: host
Oct 28 20:50:05: anw-dev
Oct 28 20:50:05: user-agent
Oct 28 20:50:05: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20070310 Iceweasel/2.0.0.3 (Debian-2.0.0.3-1)
Oct 28 20:50:05: accept
Oct 28 20:50:05: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Oct 28 20:50:05: accept-language
Oct 28 20:50:05: en-us,en;q=0.5
Oct 28 20:50:05: accept-encoding
Oct 28 20:50:05: gzip,deflate
Oct 28 20:50:05: accept-charset
Oct 28 20:50:05: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Oct 28 20:50:05: Keep-Alive
Oct 28 20:50:05: 300
Oct 28 20:50:05: connection
Oct 28 20:50:05: keep-alive
Oct 28 20:50:05: referer
Oct 28 20:50:05: https://anw-dev/members/trbmap.jsp?tkey=2&mkey=2
Oct 28 20:50:05: cookie
Oct 28 20:50:05: userid=frank; pwd=xxxxxxxxxxx; JSESSIONID=7915F7EEB596B0F95C709B9F8AD2A276
Oct 28 20:50:05: content-type
Oct 28 20:50:05: multipart/form-data; boundary=---------------------------81707749216045394012024245416
Oct 28 20:50:05: content-length
Oct 28 20:50:05: 669

The body of the request follows:

Oct 28 20:50:05: -----------------------------81707749216045394012024245416
Oct 28 20:50:05: Content-Disposition: form-data; name="ajaxreq"
<null>
Oct 28 20:50:05: uppth
Oct 28 20:50:05: -----------------------------81707749216045394012024245416
Oct 28 20:50:05: Content-Disposition: form-data; name="name"
<null>
Oct 28 20:50:05: Path Name.
Oct 28 20:50:05: -----------------------------81707749216045394012024245416
Oct 28 20:50:05: Content-Disposition: form-data; name="desc"
<null>
Oct 28 20:50:05: A description of this path goes here.
Oct 28 20:50:05: -----------------------------81707749216045394012024245416
Oct 28 20:50:05: Content-Disposition: form-data; name="mapkey"
<null>
Oct 28 20:50:05: 7
Oct 28 20:50:05: -----------------------------81707749216045394012024245416
Oct 28 20:50:05: Content-Disposition: form-data; name="closed"
<null>
Oct 28 20:50:05: on
Oct 28 20:50:05: -----------------------------81707749216045394012024245416--

Everything looks perfect, right down to the two "minus" signs terminating the request, but no file. All the documentation says to use "multipart/form-data", so I assume this is OK. Any help would be appreciated.

TIA,
anw

mdjo
10-29-2007, 05:58 PM
Ah, you're laboring under the naive delusion that JSP/servlets support file uploads. They don't. You have to write your own code to parse the file out of the request stream, or beg, borrow or steal some code to do it. Umm, I found something called "OReilly multipart" on the web once that would do this. I have some code at home that I wrote for the job (I"m at the office at the moment so I don't have it handy), if you're interested I could post it or something.