[Zope] File to ExtFile

Tim Hicks tim@sitefusion.co.uk
Thu, 14 Feb 2002 00:59:57 -0000


<Added the list back in>

----- Original Message -----
From: "urs" <ub@swissonline.ch>
To: "Tim Hicks" <tim@sitefusion.co.uk>
Sent: Wednesday, February 13, 2002 5:05 PM
Subject: Re: [Zope] File to ExtFile


> hello tim :
>
> >you aren't very specific with the problems you are having, but I'll have
a
> >guess that you are getting errors when you call manage_addExtFile() and
use
> >an existing zope object (the 'File' object) as your 'file' argument.  I
had
> >this trouble (with ExtImage as it happens), but Gregor pointed me in the
> >direction of StringIO.  If you pass in a StringIO instance containing
your
> >binary data, all should be sweet.  I think this means you'll either have
to
> >use an External Method, or allow StringIO to be imported into python
> >scripts.
>
> thanks for answering. i'm working on python-products, so StringIO is
> availible. did you use the Image.data as input to the string? i
> always have IO-errors ... thanks for more hints ...

No, I didn't use image.data.  I used index_html() after reading the
documentation on the ExtFile/ExtImage product page on zope.org.

I see you have been pointed to a much fuller response, but here is the
external method that worked for me:

------------
from StringIO import StringIO

def resizer(self):
    for old_folder in self.photos.objectValues(['Folder']):
        self.photos2.manage_addFolder(old_folder.getId())
        new_folder = getattr(self.photos2, old_folder.getId())
        for extimage in old_folder.objectValues(['ExtImage']):
            file = StringIO(extimage.index_html())

new_folder.manage_addProduct['ExtFile'].manage_addExtImage(id=extimage.getId
(), title=extimage.title, file=file, create_prev=1, maxx=400, maxy=400,
ratio=1)
-----------

hth

tim