File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Brainy Upload Bean. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Brainy Upload Bean." Watch "Brainy Upload Bean." New topic
Author

Brainy Upload Bean.

Al Hollis
Ranch Hand

Joined: Dec 12, 2005
Posts: 60
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
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

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

Joined: Dec 12, 2005
Posts: 60
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
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

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

Joined: Dec 12, 2005
Posts: 60
What do i copy the file to?

Just a bigger array of bytes?
Al Hollis
Ranch Hand

Joined: Dec 12, 2005
Posts: 60
Thanks for your help, now have program working sucessfully quite proud actually
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Brainy Upload Bean.