[Zope-DB] retrieving images from MySQL
Bobb
rawbobb at hotmail.com
Fri Jun 11 13:46:32 EDT 2004
This is how we do it (one way, anyway) ...
zsql method (called sqllogo)
select logo from table where id=<dtml-sqlvar id type=int>
python script (called logo)
result = []
lob = ['image']
for row in context.sqllogo(id=id):
lob = row['logo']
# result.append({'image': lob.read()})
# above was remmed
container.REQUEST.RESPONSE.setHeader('content-type', 'image/jpeg')
return lob
dtml method snip...
<td valign="top"><input type="image" src="logo?id=<dtml-var id>"
alt='logo'></td>
hth
bobb
----- Original Message -----
From: "Lila Klektau" <lmk at uvic.ca>
To: <zope-db at zope.org>
Sent: Wednesday, June 02, 2004 3:04 PM
Subject: [Zope-DB] retrieving images from MySQL
I am attempting to retrieve a jpeg image I placed in a LONGBLOB field of a
MySQL database. I have all the correct packages installed in Zope to
connect to a MySQL database, and the connection is successful - I am able
to get text information out of the database. I have followed the
instructions listed in the MySQL HowTo by murphy
(http://www.zope.org/Members/murphy/MySQL-BLOBs), to retrieve images, but
I can't seem to get the image to display.
The image was placed in the database using a perl script. Attempting to
retrieve it using PHP is successful, so I assume that the uploading part
of the process is correct.
To retrieve it in Zope, I am doing the following:
I have a Z SQL Method called get_grid_map which is as follows (note there
is only one column in this table):
SELECT time,map FROM status_map
I then have a python script called create_grid_map, to execute the Z SQL
Method:
result = context.get_grid_map()
container.REQUEST.RESPONSE.setHeader('content-type', 'image/JPEG')
return result[0].map
Trying to view the script results in the following error:
The image
“http://yamon.phys.uvic.ca:8080/gridCanada/gridX1/create_grid_map” cannot
be displayed, because it contains errors.
I have thought maybe an image tag in another file was necessary, but
placing the image tag <img src="create_grid_map"> in dtml, page_template,
and plain html documents all result in a broken image.
One thing I notice that is suspicious is that when I view the result of
testing my SQL statement, the image contents are "array('c','--binary
image data--'), where --binary image data-- is just a lot of binary
stuff. I'm wondering where the array part is coming from, and if that
could be my problem. When I tried verifying things in PHP and created a
file from the database contents, there was no array string prefixed and
the file displayed correctly.
Any help would be very much appreciated. Thanks!
-Lila
_______________________________________________
Zope-DB mailing list
Zope-DB at zope.org
http://mail.zope.org/mailman/listinfo/zope-db
More information about the Zope-DB
mailing list