aspose file tools*
The moose likes Servlets and the fly likes My FileUploadServlet not uploading a file if its size exceeds 1KB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "My FileUploadServlet not uploading a file if its size exceeds 1KB" Watch "My FileUploadServlet not uploading a file if its size exceeds 1KB" New topic
Author

My FileUploadServlet not uploading a file if its size exceeds 1KB

Srinivasa Maddi
Ranch Hand

Joined: Apr 18, 2007
Posts: 60
Hi there,

I wrote a servlet which will upload a text file but failing if the file size exceeds 1KB.


When i debugged, i found its failing in the while loop. Can one one tel me where i was going wrong.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
"new String(dataBytes)" is almost certainly incorrect. Files are binary data - they can't be converted to a string. And even if they are text, this call disregards the question of which encoding the file contents are in.

But more importantly, is there a particular reason you're trying to reinvent the wheel? HTTP file upload is rather complex, and has been comprehensively solved by libraries like Apache Commons FileUpload.


Ping & DNS - updated with new look and Ping home screen widget
Srinivasa Maddi
Ranch Hand

Joined: Apr 18, 2007
Posts: 60
reason being, my requirement is demanding me not to go with any third party software though its free.
Rajat Raina
Greenhorn

Joined: Feb 17, 2009
Posts: 10
You can set the max size of your file more than 1KB.
The function is setSizeMax(size) but for this you have to use DiskFileUpload.


To be a winner first you need to be a begineer.
Raina Rajat
SCWCD (95%)
SCJP(70%)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
I would question that requirement. It is a waste of your time to do this all over again.

But certainly you could use the source of that library (or of any other of the multiple available ones) as inspiration for your solution.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Srinivasa Maddi wrote:reason being, my requirement is demanding me not to go with any third party software though its free.

I really don't understand why ones always come up with such lame excuse? Where does this aversion come from?

Apache Commons FileUpload is a well developed and thoroughly tested file upload API. Honestly, with the knowledge you've shown as far, you would require and waste too much time to achieve the same robustness as Apache Commons FileUpload. That isn't worth the effort.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: My FileUploadServlet not uploading a file if its size exceeds 1KB
 
Similar Threads
moving files over the network
Not able to convert large sized byte array to String
error in uploading zip file
Type conversion between Bytes and Strings
Uploading a text file to a blob in MySql, then downloading that file to local file system