[Zope] Cannot show blob image from sql server

Chris Withers chris at simplistix.co.uk
Thu Oct 27 12:34:04 EDT 2005


Thomas G. Apostolou wrote:
> i have made an external method to connect and get data from an sql
> server 2000, and then show them in a table. All works fine but one of
> the columns i retrieve is a BLOB image witch makes my external method
> to crash. So i used z SQL Method (witch is not prefared because there
> is a lot of customization and that's why i used External Method with
> Python from the begining) and it goes fine with retrieving and showing
> the data. But still i cannot show the BLOB image as image. It shows as
> a very very long string.

You will need to do at least one query for the data and one request for 
each of the images.

eg, you "main method" returns html like:

<table>
   <tr>
    <th>
      Name
    </th>
    <th>
      Picture
    </th>
   </tr>
   <tr>
    <td>
      Test User
    </td>
    <td>
      <img src="http://localhost:8080/myproject/getImage?id=1231"/>
    </td>
   </tr>
</table>

You then need to implement getImage to:
- do the SQL select to get the image data based on the id
- write this data to the RESPONSE object
  (see lib/python/OFS/Image.py's index_html method for an example)
- set a content-disposition header so that the browser does the right
   thing

Hopefully soon you'll realise the fundamental issue with http that 
you're bumping into: you don't return a fully rendered page, you return 
a page with references in it to css/javascript/image files that are used 
to render the final page, and that storing binary data in relational 
databases is evil ;-)

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk


More information about the Zope mailing list