[Zope] Displaying BLOB's with Zope
Mark Evans
mark.evans.b@bayer.com
Wed, 29 Jan 2003 16:25:49 -0800
Hi all,
I have been reading everything I can find on the web on this and just c=
an't find
exactly what I need. I hope someone can help.
I have recently begun learning about BLOBs in Oracle8i. I have success=
fully
created a table 'blobtest' consisting of two fields, 'ID' and 'Image' a=
nd loaded
a jpeg file into it using sqlloader. I am using DCOracle2, Zope2.5.1,M=
ozilla1.x
and Python2.2.1. Zope and Oracle are running on Solaris and my client =
is W2K.
I have an external method called 'blobtest' that retrieves the blob:
import string, DCOracle2 as dco
def main ():
dCon =3D dco.connect("foo/moo@myfoo")
dCur =3D dCon.cursor()
sql =3D "select image from blobtest where id=3D'1'"
dCur.execute(sql)
result =3D dCur.fetchone()
lob =3D result[0]
pic =3D lob.read()
return pic
I have a DTML method that calls the External Method:
<dtml-var standard_html_header>
Method 1: Display image in-line, retrieved by External Method<BR>
<img src=3D&dtml-blobtest;>
</p>
<dtml-var standard_html_footer>
What I want it to do is display the image on the html page. What it do=
es is
open a browser dialog box asking me to select an application to open a =
file of
type 'application/octet-stream'. If I select an image viewing program =
like
IrfanView, Irfan tells me the file is of type jpeg, but missing the fil=
e
extension. When I click 'ok' it displays the correct image and display=
s it
properly.
This leads me to suspect that a) the blob that is returned does not hav=
e a name
and therefore doesn't have a file type extension and b) my problem prob=
ably has
something to do with setting the content-type header properly to image/=
jpeg.
How do I do this using an external method?
Alternatively, I have tried to adapt the MySQL HowTo by murphy (
http://www.zope.org/Members/murphy/MySQL-BLOBs) in the following way:
Created a python script called 'retrieveImage':
photo =3D context.getImage()
container.REQUEST.RESPONSE.setHeader('content-type', 'image/jpeg')
return photo[0].image
which calls the ZSQL method 'getImage':
select image from blobtest
where id=3D'1'
When I click on the 'test' tab for the python script, I get the followi=
ng
message:
The image "http://foo.com/blobtest2/retrieveImage" cannot be displayed,=
because
it contains errors.
What am I missing here? Thanks in advance for the help.
Regards,
Mark Evans=