[Zope] ExtImage madness - upload fails from script (python)

Tim Hicks tim@sitefusion.co.uk
Wed, 16 Jan 2002 23:14:44 -0000


I'm running zope 2.3.3 on redhat 6.x with ExtFile 1.1.3 (no patches)
installed and working with PIL.  Extfile appears correctly installed in the
Control_Panel/Products list, and I can successfully add an instance from the
ZMI - including creating the thumbnail.

So now, I'm trying to upload from an image (actually, potentially several)
from a form of my own.  The form POSTs to a script (python) which does
numerous other things, and then tries to do a manage_addExtImage().  Here is
the relevant code...

----
request = context.REQUEST
f_request = context.REQUEST.form
photos = ['photoUpload1', 'photoUpload2', 'photoUpload3']

try:
  prop_id = str(f_request['PROPERTY_ID'])
  if hasattr(getattr(context, context.root()).photos, prop_id):
    #The folder already exists, so we don't need to do anything
    pass
  else:
    #We need to add a folder to hold all photos for this property
    getattr(context, context.root()).photos.manage_addFolder(prop_id)
  photo_folder = getattr(getattr(context, context.root()).photos, prop_id)
  #Need to iterate over 'photos' and to add them all
  for photo in photos:
    if len(request.form[photo].read()) == 0:
      #The form was submitted without a file for this field
      pass
    else:
      #They all need unique id's... I'm going with integers
      intid = 1
      while 1:
        if hasattr(photo_folder, str(intid)):
          intid = intid + 1
        else:

photo_folder.manage_addProduct['ExtFile'].manage_addExtImage(file=request.fo
rm[photo], create_prev=1, maxx=50, maxy=50, ratio=1)
          break
--------

Obviously, this is an abridged version of a much longer script.

Anyway, the upshot of submitting my form is that an ExtImage instance is
added in the correct place but of zero size (in bytes) - i.e. none of the
data actually gets added.  However, to prove that I'm almost there, the
instance does actually have an ID = filename_from_client_machine and title =
path_from_client_machine.  The infuriating thing is that I've had this
working before, but broke it somewhere along the way and don't know when or
how.

Please... I'm tearing my hair out over this one.

cheers

tim