[Zope] storing images

Tim Hicks tim@sitefusion.co.uk
Sat, 24 Aug 2002 12:05:12 +0100


> Hello zope,
>
>   i want to store images, and call them by id.
>   it needs to be used from other places, so it will go in a mysql
>   table, base64 encoded.
>
>   how to write a function, that gets the image by id, and returns it
>   to the browser with the correct content type?
>
>   i should use a python script for that? or can it be made in dtml or
>   pt?
>
>   how to make it respond to this?
>
>   http://zopehost/images/image_id.jpg
>
>   or something similar? ... with 'images' being the script....

>From a python script, you can use the 'traverse_subpath' binding to get hold
of those elements of the url after that of the script itself.  I believe the
elements are returned as a list or tuple, so you access them like

traverse_subpath[0]

which in your example, would give you 'image_id.jpg'.  You could then pass
this as an argument to a zsql method in order to return the correct image.

However, if you are getting several images, this could get expensive as
several database queries would be performed.  Perhaps you'd be better
storing the images on the filesystem and using something of the LocalFS ilk
to access them from zope.  Being on the filesystem, you could of course make
them accessible to to the other applications that you speak of.

Just an idea

tim