Newbie: Getting Image From Disk into Buffer

A

Ashley Lloyd

I have been trying to get an image into an interbase database (see earlier
post), and came across a post made on a list some time ago (I ignored it
earlier as we use kinterbasDB not gvib, but I thought I'd try using it in
kinterbasDB anyway):

________________________________________________________________
<snip>

I think I can provide some information. I have added a jpg to an interbase
table and have successfuly displayed it in ZOPE. First off you may know
that Interbase does not store BLOB data directly in a table's blob column.
It stores the data elsewhere and then stores a "pointer" to it in the
table column. This means that BLOB data MUST be inserted via program code
and thus you cannot do the following in a Zope SQL Method:

insert into the_table (blob_column) values (blob_data)

If you are using the gvibDA you can code an external method to do this:

import gvib
cn = gvib.connect(...)
cr = cn.cursor()
cr.execute('insert into the_table (blob_column values (?)', (blob_data,))
cn.commit()
cr.close()
cn.close()

</snip>
________________________________________________________________

I apologise for my ignorance (newbie, sorry), but can anyone tell me how it
is that you get the image from disk into blob_data? I have tried several
ways of opening up the image into a buffer, but it always seems to place
into the database a string of either the name of the image on disk
('c:/image.bmp', say), or text such as the following:
<open file 'c:/image.bmp', mode 'rb' at 0x009F06A0>

Once again I apologise for my stupidity (and for making 3 requests today - I
am trying to figure them out myself, honest!), but if someone could tell me
how I get the image into blob_data (which I assume is a buffer), I'd be very
grateful.

TIA

Ashley

_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today!
http://www.msn.co.uk/messenger
 
D

David Rushby

Ashley Lloyd said:
I have been trying to get an image into an interbase database (see earlier
post), and came across a post made on a list some time ago (I ignored it
earlier as we use kinterbasDB not gvib, but I thought I'd try using it in
kinterbasDB anyway):
...
it always seems to place
into the database a string of either the name of the image on disk
('c:/image.bmp', say), or text such as the following:
<open file 'c:/image.bmp', mode 'rb' at 0x009F06A0>

In the 'c:/image.bmp' case, you're inserting the file's name (string);
in the "<open file 'c:/image.bmp', mode 'rb' at 0x009F06A0>" case,
you're inserting an open file object, which is repr()ed into a string
for storage. Instead, you need to insert the *contents* of the file
as a string, e.g., the return value of the file object's read()
method.
... but if someone could tell me how I get the image into blob_data
(which I assume is a buffer), I'd be very grateful.

http://sourceforge.net/forum/forum.php?thread_id=889866&forum_id=30917
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top