[Zope-DB] Loading an image in zope]

Cliff Ford Cliff.Ford at ed.ac.uk
Thu Mar 17 02:43:07 EST 2005


A simple solution:

1. Create a python script in the Extensions directory (folder)  of your
installation, giving it a suitable name, such as getDocument.py (make
sure the zope user has read permission):

def getDocument(filename):
     file = '/any/common/path/name/'+filename
     input = open(file, 'r')
     content = input.read()
     input.close()
     return content

2. Create an External Method in the folder in which you wish to view
images, or in its parents. The External Method just uses the module name
and the function name. Give it a suitable id, say getDiskImage.

3. Create a python script in the same folder, to be called to fetch the
image. Call it say getImage:

# get the image details from the database
for result in context.getImageSQL():
     # mimeType is another external function that gets the mime type
     # it could be set manually to application/jpeg
     # check this - my memory is fuzzy
     (type, encoding) = context.getMimeType(result.Filename)
     context.REQUEST.RESPONSE.setHeader('Content-Type', type)
     context.REQUEST.RESPONSE.setHeader('Content-Disposition', 'inline;
filename='+result.Filename)
     return context.getDiskImage(result.Filename)


4. In your web page make the image tag look like this:
<img src="getImage?SerialNo=nn" width="xxx" height="yyy" alt="Whatever">
where SerialNo is the database table record number of the image.

This is a simplified version of something I use, so I may have
introduced errors in the simplification.

HTH

Cliff

srikanth wrote:
> 
> 
>>Your question is a bit too vague for a precise answer. What database
> 
> are 
> 
>>you referring to - it could be the ZODB (Zopes own object database), an
> 
> 
>>external relational database that you are trying to get images into and
> 
> 
>>out of (like Oracle, Postgres or MySQL) or just a collection of images 
>>stored as files?
> 
> 
>    Sorry for not being so precise. I am using MySQL database. The
> filepath is stored in the mysql database but the physical files are
> stored on the harddrive outside zope in .jpg files. I need to diplay the
> file in zope web page.
> 
> 
> 
>>Are you stuck trying to upload an image to Zope, or 
>>displaying an image in a web page?
> 
>    First I don’t know if zope can access file which on the hard disk
> outside zope (sorry but I don’t know). I search the database and get the
> filepath from the database. But physical file is sitting somewhere on
> the harddisk and I need to display it in the result page.
> 
> Could you plz help me out. Ta.
> 
> 
> 
> 
> If the images are in the ZODB you use a standard img tag for display. If
> 
> the images are elsewhere you need a script to get the image for display,
> 
> either from a relational database or the file system. There are also 
> products for managing images.
> 
> Cliff
> 
> srikanth wrote:
> 
>>Hi 
>>
>> 
>>
>>I am new to zope. I am developing a small site for my company.In my
> 
> site
> 
>>I need to load an image whose path is stored in the database somewhere
>>on the harddisk.
>>
>>How would I be able to do that. Because I tried and zope doesn’t show
>>any image even if the path Is correct one. 
>>
>> 
>>
>> 
>>
>> 
>>
>>Any help would be greatly appreciated. 
>>
>>ta
>>
>>
>>---
>>Outgoing mail is certified Virus Free.
>>Checked by AVG anti-virus system (http://www.grisoft.com).
>>Version: 6.0.859 / Virus Database: 585 - Release Date: 2/14/2005
>> 
>>
>>
>>
>>
> 
> ------------------------------------------------------------------------
> 
>>_______________________________________________
>>Zope-DB mailing list
>>Zope-DB at zope.org
>>http://mail.zope.org/mailman/listinfo/zope-db
> 
> _______________________________________________
> Zope-DB mailing list
> Zope-DB at zope.org
> http://mail.zope.org/mailman/listinfo/zope-db
> 
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.859 / Virus Database: 585 - Release Date: 2/14/2005
>  
> 
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.859 / Virus Database: 585 - Release Date: 2/14/2005
>  
> 
> 
> 



More information about the Zope-DB mailing list