aspose file tools*
The moose likes Servlets and the fly likes Upload File Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Upload File Servlet" Watch "Upload File Servlet" New topic
Author

Upload File Servlet

Ramesh Sahu
Ranch Hand

Joined: Jul 14, 2008
Posts: 32
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
Marshal

Joined: Mar 22, 2005
Posts: 42632
    
  65
Handling HTTP file uploads is way more complicated that you think it is. A library like Apache Commons FileUpload makes it real easy, though.


Ping & DNS - my free Android networking tools app
Ramesh Sahu
Ranch Hand

Joined: Jul 14, 2008
Posts: 32
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
Marshal

Joined: Mar 22, 2005
Posts: 42632
    
  65
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

Joined: Jul 14, 2008
Posts: 32
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 .

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Upload File Servlet