Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to upload file using Commons HTTPClient and Commons FileUpload

 
Amit Savani
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Amit Vinod Dali
Ranch Hand
Posts: 42
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
 
Amit Savani
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think form-data is the correct type to use here, since you're really submitting a form.
 
Amit Savani
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you may modify the client code posted earlier like this:
postMethod.setRequestHeader("Content-type", "multipart/form-data;boundary=---------------------------sdjkahdj294919323195");
 
duan haowei
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or you can annotate the line:method.addRequestHeader("Content-type", "multipart/form-data" );//multipart-mixed
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic