aspose file tools*
The moose likes Other Open Source Projects and the fly likes Unable to upload file using Commons HTTPClient and Commons FileUpload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Unable to upload file using Commons HTTPClient and Commons FileUpload" Watch "Unable to upload file using Commons HTTPClient and Commons FileUpload" New topic
Author

Unable to upload file using Commons HTTPClient and Commons FileUpload

Amit Savani
Greenhorn

Joined: Mar 02, 2009
Posts: 17
Hi,

I am trying to send some parameters and a file to the server using Commons HTTPClient (V 3.1). On the server end I am using Commons fileupload( V 1.1.1.1) to get parameters and file. I am getting following exception


Here is Client code



Server Code


Do any one have idea what could be the problem and possible resolution?

Regards
SCJP 1.4, SCBCD 5.0
Amit Vinod Dali
Ranch Hand

Joined: Apr 14, 2010
Posts: 42
The following link will help you:
http://www.devdaily.com/java/jwarehouse/commons-fileupload-1.0/src/java/org/apache/commons/fileupload/FileUploadBase.java.shtml
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

This Servlet file upload tutorial may help you.


[Servlet tutorial] [Servlet 3.0 Cook Book]
Amit Savani
Greenhorn

Joined: Mar 02, 2009
Posts: 17
sudhir nim wrote:This Servlet file upload tutorial may help you.


Thanks for reply. Actually I am able to upload file form html code but I want same scenario using Commons HTTPClient which right now not working
Amit Savani
Greenhorn

Joined: Mar 02, 2009
Posts: 17
sudhir nim wrote:This Servlet file upload tutorial may help you.


Thanks for sharing. I found following code in FileUploadBase class which is throwing error.


Now I wonder what is problem with code where I set content type as multipart/form-data or multipart/mixed?

On the other hand if I submit same data with html form having enc-type="multipart/form-data" it's work fine.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I think form-data is the correct type to use here, since you're really submitting a form.
Amit Savani
Greenhorn

Joined: Mar 02, 2009
Posts: 17
Here I modified client code, used deprecated method and it worked. Below is the code


But I still wonder what is the problem with the client code I posted earlier?
duan haowei
Greenhorn

Joined: Mar 26, 2012
Posts: 2
you may modify the client code posted earlier like this:
postMethod.setRequestHeader("Content-type", "multipart/form-data;boundary=---------------------------sdjkahdj294919323195");
duan haowei
Greenhorn

Joined: Mar 26, 2012
Posts: 2
or you can annotate the line:method.addRequestHeader("Content-type", "multipart/form-data" );//multipart-mixed
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to upload file using Commons HTTPClient and Commons FileUpload