• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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.
 
Srinivasa Maddi
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
reason being, my requirement is demanding me not to go with any third party software though its free.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic