• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Brainy Upload Bean.

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Was wondering if any one has similar experiances with this bean...

I have the following code based on....

OnJava Upload Bean



Now this code works perfeclty with basic text files, but for images and pictures it seems to get more information than actually there, e.g a 76kb jpeg image becomes 120kb....

Any one know why this is doing this, or can point me in a better direction. I dont really want to use one of these jsp upload beans, and orielly wont work with the java version installed on the machine when program is to be run, and again is allready all there something i dont want to have Thanks in advance
[ December 12, 2005: Message edited by: Al Hollis ]
 
Sheriff
Posts: 28394
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're using Readers and Writers, which are specifically meant for text only, to operate on binary data such as image files. Which are not text, so they get damaged when you do that. Change your code to use InputStreams and OutputStreams; they will work for text files as well.
 
Al Hollis
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much was doing my head in lol.... Should have read the api's

Now i have a problem...

How big can i set my byte array...

byte[] line = new byte[5242880];

Does that equal 5 megs?? if so why when i upload a 1.2 meg pdf do i only recieve 78k??

Thanks in advance
 
Paul Clapham
Sheriff
Posts: 28394
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't try to get the file in one bite. Assign a reasonable-sized buffer and copy the file in a loop.
 
Al Hollis
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do i copy the file to?

Just a bigger array of bytes?
 
Al Hollis
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help, now have program working sucessfully quite proud actually
 
reply
    Bookmark Topic Watch Topic
  • New Topic