You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Catalin Kormos <ca...@yahoo.com> on 2005/12/21 16:23:09 UTC

Multipart Post to ASP form

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?
  
  Thanks,
  Catalin
  

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com