Wayne,
multipart/form-data is a special MIME type used to upload files using HTML
forms, which is quite complex in order to multiplex many form values (some
of which may be files) into a single upload stream. You'd need to write code
for the client side to do the inverse of what MultipartRequest does on the
server side to get MultipartRequest to work.
I think (from memory) Jason's HttpMessage class uses x-www-url-form-encoded,
another complex(ish) encoding to upload forms _without_ files. They are
different and not compatible.
If you just want to upload a file by itself, you can avoid these complex
encodings and just roll some of your own code using HttpUrlConnection and a
simple servlet to read the data at the other end (i'd use HTTPMessage as a
base/example).
If you need to upload a file AND some other values, you can write you own
simple "encoding", or implement the client code I referred to before, the
spec is in the RFC mentioned in Jasons code.
Cheers
geoff
----- Original Message -----
From: "Wayne Elliott" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, February 21, 2000 3:38 PM
Subject: Call file upload servlet from Java app?
> I am looking at the UploadTest servlet from Jason Hunter's Java Servlet
> Programming. This works fine using a html form like this ...
>
> <FORM ACTION="/wpe/servlet/UploadTest" ENCTYPE="multipart/form-data"
> METHOD=post>
> What is your name? <INPUT TYPE=TEXT NAME=submitter> <BR>
> Which file do you want to upload? <INPUT TYPE=FILE NAME=file> <BR>
> <INPUT TYPE=SUBMIT>
> </FORM>
>
> However, I would like to call this servlet from within a Java program.
>
> I tried to use Oreilly's HttpMessage class to call the servlet...
>
> urlStr = "http://localhost:8080/wpe/servlet/UploadTest";
> URL url = new URL(urlStr);
> HttpMessage msg = new HttpMessage(url);
> Properties props = new Properties();
> props.put("submitter", "wayne");
> props.put("file", "c:\\kuz7.jpg");
> InputStream in = msg.sendPostMessage(props);
>
> At this point I get an exception regarding it not being
> multipart/form-data.
>
> I tried modifying HttpMessage (where the Netscape bug fix code is)
> to get the content type right. Then I go a "missing boundary" error.
>
> I then tried setting the content type in HttpMessage thus
>
> con.setRequestProperty(
> "Content-Type", "multipart/form-data;
> boundary=---------------------------2799030872219");
>
> At this point the java app just hangs there, ruminating on its purpose.
>
> The multipart aspect of the called servlet seems to be the problem.
> If I could just understand what information the form is sending, perhaps
> I could emulate it better from within Java.
>
> I feel I am loitering in hack city, drifting further and further away
> from the simple truth I need to proceed. Can someone explain what needs
> doing to get this app to work.
>
> WPE
>
>
___________________________________________________________________________
> 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