• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Unable to upload file using Commons HTTPClient and Commons FileUpload

 
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?
 
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.
 
Author
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?
 
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
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!