Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Upload File Servlet

 
Ramesh Sahu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I want to upload a simple file from a html to a webserver running on apache tomcat.
I used html tag <input type="file" name="upload_file" /> to select and post my request to servlet.

In the servlet used the ServletInputStream of the request to write the bytes to any particular file. The file is getting created in the server but it's content seems to be missing.

Can anyone tell me what is wrong with my approach ?? Any help is truely appreciable.

Uploading Servlet portion

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Handling HTTP file uploads is way more complicated that you think it is. A library like Apache Commons FileUpload makes it real easy, though.
 
Ramesh Sahu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Handling HTTP file uploads is way more complicated that you think it is. A library like Apache Commons FileUpload makes it real easy, though.


Thanks for the reply....

Actually I was expecting the reason behind it. I have a stream of data , then why can't I direct it into any destination???
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the stream of data contains other data in addition to the actual file contents. Under the "specification URLs" link in my signature you can find the HTTP file upload spec - it's not trivial!
 
Ramesh Sahu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Because the stream of data contains other data in addition to the actual file contents. Under the "specification URLs" link in my signature you can find the HTTP file upload spec - it's not trivial!


Thanks a lot . It seems to clear the air .

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic