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

Brainy Upload Bean.

 
Al Hollis
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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 ]
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Thanks for your help, now have program working sucessfully quite proud actually
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic