[Zope-DB] Displaying BLOB's with Zope
Matthew T. Kromer
matt@zope.com
Thu, 30 Jan 2003 10:09:20 -0500
I removed the cross-post; this is going to Zope-db only.
Mark Evans wrote:
><dtml-var standard_html_header>
>Method 1: Display image in-line, retrieved by External Method<BR>
><img src=&dtml-blobtest;>
></p>
><dtml-var standard_html_footer>
>
>
This doesn't work because your blobtest method doesn't set the content
type. Generally you want your LOB image objects to look something like
<dtml-call RESPONSE.setHeader('content-type','image/jpeg')
><dtml-var expr="sqlMethodToGetLob().lobcolumn.read()">
What you were trying to do is say <img src="blobdata...."> which wont
work, src= needs to be a URL.
>Created a python script called 'retrieveImage':
>
> photo = 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='1'
>
>When I click on the 'test' tab for the python script, I get the following
>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.
>
>
Offhand, that looks right to me, so I dont know what it is unhappy
about. Perhaps you need to specify context.REQUEST vs
container.REQUEST, although I dont really think it should matter, both
should be able to acquire REQUEST. Perhaps when you return
photo[0].image you really need to return photo[0].image.read().
N.B.
I'm fairly sure (but I dont exactly recall) that I put an implicit read
into DCOracle2's LOB objects when they get shuffled out to Zope, which
removes the need to explicitly call read() on them -- the act of trying
to str() the lob object should cause it to get read.