[Zope] External methods and images

jhauser@ifm.uni-kiel.de jhauser@ifm.uni-kiel.de
Tue, 11 May 1999 11:38:31 +0200 (CEST)


Tony McDonald writes:
 > 
 > Ah, that might explain it. Only problem is that I'm using 
 > Zope-1.11.0pr1 and there aren't enough lines in ExternalMethod.py
 > 
 > All I really want to do is pass the name of an image to an external 
 > method which then extracts it from a directory, wraps it up in the 
 > content-type magic and sends it back to me. Does anyone have 
 > something like it working? Any pointers gratefully received.
 > 
 > TIA
 > Tone
I have played with external methods to get a gallery going. I wrap the 
uploaded file from the REQUEST into a subclass of File. The loading
looks like this:

def em_addpic(self, REQUEST):
    """\
    Add a picture object to the local folder, represented by (self)
    """
    try:
        pname = REQUEST['title']
        mapped_name = get_uni_id(pname)
        fobj=GalleryPic(mapped_name, pname, REQUEST['file'], content_type=_ftype(pname))
        fobj._set_descr(REQUEST['descr'])
        fobj._mk_thumb() # Should be called from  __init__
        self._setObject(mapped_name, fobj)
    except:
        import sys
        return  sys.exc_type, sys.exc_value 

    if REQUEST is not None:
        return MessageDialog(title='Picture added to Gallery.',
                             message='Picture %s added to Gallery.' % (pname,),
                             action='%s/showgal' % REQUEST['URL1']
                             )

_ftype is taken from the fsimport.py external method, it looks only
for the extension of pname in a dictionary, if you know the content
type then it would be easy. GalleryPicis the subclass of File, it
holds a reference to an external picture and puts a thumbnail into the 
database. Look into the File class. The actual data is wrapped into a
class, which can be used to read from the filesystem.

HTH,

__Janko