[Zope] Images and database

Paul Zwarts paz@oratrix.com
Tue, 24 Jul 2001 09:41:17 +0200


Greetings Cristoph,

There are ways around it, but the typical problem with storing images in a
database is the caching. An image must be read from the dbase to temp
storage and then to the client. This prevents immediate caching and
increases load across the dbms. What I prefer to do is store a single word
in a record like the country flag name. Then in your dtml, the record pulls
only a piece of text that is part of the url to the image. For instance:

<dtml-in whateverMethod>
  <dtml-var data>
  <img src="http://yourserver.com/Images/Flags/&dttml-countryname;.gif">
</dtml-in>

This allows for dynamic flag calls and allows the client to cache (if you
use the caching mechanism or other technique)

So basically, you can modify the typical country-table that will access a
file by the 2-char country code (dont use 2, its outdated). Leaves you only
to decide where to place the IT.gif, NL.gif, DE.gif and so on.....


Success,
Paz


-----Original Message-----
From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of
Christoph Schirmer
Sent: Tuesday, July 24, 2001 8:43 AM
To: zope@zope.org
Subject: [Zope] Images and database


I am using a mysql database. Actually the sql queries with zsql are by
far the easiest part in learning Zope :-)
Anyway, I have the following problem. Some of the data also need to be
associated with pictures. E.g. for countries, there
are flags. Where should one at best store the flags? I thought it
could be better to store them within Zope, so that they files can be
used easily outside the database as well.
In the site root I created a folder images, and as id I used the short
tag of the country (e.g. ITA for Italy), which can be
found in the field cou_tag.
The method looks like this:
<tr><th>Country-ID</th><th>Tag</th><th>Country</th><th><a
href="listbycontinent">Continent</th><th>&nbsp;></tr>

<dtml-in countries>
<tr><td><dtml-var cou_id></td><td><dtml-var cou_tag></td><td><dtml-var
cou_name></td><td><dtml-var con_name></td><td><img
src="&dtml-portal_url;/images/<dtml-var cou_tag>" ALT="<dtml-var
cou_name>" align="absmiddle"></td></tr>

</dtml-in>
</table>

It is probably rude, but I am a newbie :-). And it works, basically, but
it is awfully slow, because for each entry it
searches the images folder for a file.

Is there a way to make this more elegant, and faster?

Thanks for your help,
Christoph