db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Bowen <s...@yahoo.com>
Subject Re: How to save / load LOBs in Postgres with Torque
Date Wed, 03 Nov 2004 14:45:28 GMT
That did it, thanks very much! I tried changing my
code to look more like yours:

File file = new File("file");
BufferedInputStream bis = new BufferedInputStream(new
FileInputStream(file));
byte buf[] = new byte[new
Long(file.length()).intValue()];
while ((s = bis.read(buf, 0, 2048)) > 0) { ... }

... but it doesn't seem to work. So I am sticking with
just using a FileInputStream.

Many thanks for your help!

syg 


--- Saravana Krishnan <saravkrish@uky.edu> wrote:

> Robert,
> 
> I can see one obvious mistake... but may be I'm
> wrong.
> 
> > byte buf[] = new byte[2048];
> > int s, tl = 0;
> > while ((s = bis.read(buf, 0, 2048)) > 0) {
> >    tl += s;
> > }
> > 
> > myDAO.setLOBField(buf);
> > myDAO.save();
> > 
> 
> Your byte array buf[] is always a 2KB in size
> irrespective of the file
> size! I expect any 1 page Word Doc to be way larger
> than 2 KB. You
> should do something like -
> 
> File binaryFile = new File(filename);
> FileInputStream fistream = new
> FileInputStream(binaryFile);
> byte[] filedata = new byte[(int)
> binaryFile.length()];
>  
> fistream.read(filedata);
> fistream.close();
> imgdb.setData(filedata);
> 
> It atleast works for me! I tried it for around 5MB
> image file. I guess
> the problem is with your code (no offense - we all
> make mistakes ;-) and
> not Torque.
> 
> 
> > And to load it I do the following:
> > 
> > byte buf2[] = myDAO2.getFitxer();
> > OutputStream out = new FileOutputStream("myFile");
> > out.write(buf2);
> > out.close();
> 
> The code for loading seems to be fine because Torque
> (actually JDBC I
> guess) creates the array for you.
> 
> > 
> > .... And all I get is a bunch of junk when I open
> it in
> > Word. 
> > 
> 
> Expected!
> 
> Hope it helps.
> 
> ~Sarav
> P.S: Ben, a reply to your question will be a long
> mail. Don't have time
> yet. Will do when I get time.
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail:
> torque-user-help@db.apache.org
> 
> 



		
__________________________________ 
Do you Yahoo!? 
Check out the new Yahoo! Front Page. 
www.yahoo.com 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message