On Thu, Dec 22, 2005 at 12:14:23AM -0800, Catalin Kormos wrote:
> Hi there,
>
> I have and ASP form used to upload files to the web server, that contains
> an input field of type "file"; i would like to build an application that
> uses this form, so my users don't need to go in the browser to perform one
> upload at a time. Looks like anything i do, it doesn't work, here is a
> snippet of my code:
>
> HttpClient client = new HttpClient();
> PostMethod filePost = null;
> try
> {
> File targetFile = new File(System.getProperty("user.dir"),
> "/images/tn_CIMG2690.JPG");
>
> filePost = new PostMethod("http://...");
>
> Part[] parts = {new FilePart(targetFile.getName(),
> targetFile)};
> filePost.setRequestEntity(new MultipartRequestEntity(parts,
> filePost.getParams()));
>
> int status = client.executeMethod(filePost);
>
> System.out.println(status);
> if (status == HttpStatus.SC_OK) {
> System.out.println("Upload complete, response=" +
> filePost.getResponseBodyAsString());
> } else {
> System.out.println("Upload failed, response=" +
> HttpStatus.getStatusText(status));
> }
>
> }
> catch (Exception exc)
> {
> exc.printStackTrace();
> }
> finally {
> // release any connection resources used by the method
> filePost.releaseConnection();
> }
>
> The server responds back with OK always, but the file doesn't get
> uploaded.
>
> Do you guys have a working example for this kind of use case? i'm sure
> this has to be working, maybe i'm missing something obvious?
>
Here's a sample app you can use as a reference
http://svn.apache.org/viewcvs.cgi/jakarta/commons/proper/httpclient/trunk/src/examples/MultipartFileUploadApp.java?view=markup
BTW, have you tried if this actually works with a browser?
Oleg
> Thanks,
> Catalin
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]