[ZPT] displaying images from a postgres table

Tino Wildenhain tino at wildenhain.de
Mon Sep 13 02:02:25 EDT 2004


Hi Kenneth,

Am Mo, den 13.09.2004 schrieb Kenneth Gonsalves um 6:04:
> hi,
> i have a postgres table where one of the fields is a bytea (jpeg image). I 
> cannot get this image to display on a zpt template. Some problem with the 
> header? any clues?

This is not related to ZPT or whatever.
You dont include the data inline - you
refer to the image by URL.

So you need something to actually produce
the image (and only the image, not any HTML)

For example a python script like this:

imagename="/".join(traverse_subpath)
request=context.REQUEST
response=request.RESPONSE


res=ZSQLMethodTOQueryDB(imagepath=imagename)

if res:
    data=res["byteadataforimage"]

    # now lets assume all images are gif
    response.setHeader("Content-Type","image/gif")
    return data

If you have gif, jpeg all mixed either you have
the hint about this in the DB too or guess
it from the name (if you save with extensions)
or you read the first few bytes of data and decide.

The script above cann be called via

path/to/TheScript/someimage

someimage goes to traverse subpath
and in the script, imagename="someimage"
If you have more path elements, in my
example they are concenated via /

HTH
Tino Wildenhain



More information about the ZPT mailing list