db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Saravana Krishnan <saravkr...@uky.edu>
Subject Re: How to save / load LOBs in Postgres with Torque
Date Tue, 02 Nov 2004 17:52:38 GMT

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()];

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. 


Hope it helps.

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

View raw message