Mailing List Archive

[Zope-PTK] Upload images into ZClass based objects
Hi,

Does anyone know the best way to add support for binary files
to the PTK?

First I would like to add support for the inclusion
of gif/jpeg uploads into PTK derived objects. The existing
Document ZClass allows for the upload of text & html with
python code like below:

if file:
if type(file) is not type(''):
file=file.read()
if file:
self.text=file
self._parse()

Were file is a string path to a file local to the
clients browser. Now this code still does not work when
the document object is first created (another problem) but
does work when the document object is edited.

I looked through many of the files in the standard Zope
install (Image.py, load_site.py, ImageFile.py) and cannot
seem to get any of those functions to work. It looks like
manage_addImage in Image.py is closest but what is the right
python syntax to call this in my ZClass file?

if imgfile:
if type(imgfile) is not type(''):
manage_addImage('imgs/Pimage', imgfile, REQUEST=_.None)

Now, the ideal solution would allow all gif/jpef files to be
stored in the external file system and not inside the ZODB.
Does anyone know a way to allow the user to browse a local
file using a normal <input type="file"...> button and then
automagically upload the file to overwrite existing or create
a new file outside the ZODB. At the same time create a new
Zope object or update existing object with meta info about
the uploaded item. Elements of the new LocalFS product look
promising but do not support upload/writing to the files.

Right now I need to get gifs/jpegs uploaded into an existing
ZClass but, I do not want my ZODB to ballon so need a follow
along better solution.

Thanks for any pointers.

Chip Vanek
e-Mail: chip@upcast.com
Re: [Zope-PTK] Upload images into ZClass based objects [ In reply to ]
On Sun, 19 Mar 2000, Chip Vanek wrote:

> Hi,
>
> Does anyone know the best way to add support for binary files
> to the PTK?

Are you unhappy with the provided Image and File PTK objects? They
provide almost the same behaviour as the standard Zope ones. In fact,
they extend the standard ones, but perform some 'behaviour modification'.

> First I would like to add support for the inclusion
> of gif/jpeg uploads into PTK derived objects.

I'm sure I am not understanding you... You want the PortalContent
class to manage a set of images?

> The existing Document ZClass allows for the upload of text & html with
> python code like below:

If you have a Document ZClass, you are using a very old PTK. There
are no ZClass content objects presently, and haven't been since before
IPC8...

> It looks like manage_addImage in Image.py is closest but what is the
> right python syntax to call this in my ZClass file?

manage_addImage is inserted as a method in PortalFolder. ...Wait a
moment, no it's not. 'addImage' (from ZopePTK/PTKBase/Image.py) is.
Maybe we're not talking about the same thing at all. I'll pretend we are.
;-)

It's called on the folder you wish to add the image to. It could be
used from Python like this (as an external method):

def populate_folder(self, filename):
file = open(filename).read()
self.addImage('id', file, 'Title', 'Description of this image')

(There are a couple more arguments with default values, see the
source.)

> Does anyone know a way to allow the user to browse a local
> file using a normal <input type="file"...> button and then
> automagically upload the file to overwrite existing or create
> a new file outside the ZODB.

I'll leave this to someone with some experience in this sort of
thing.

Mike.

--
Mike Pelletier email: mike@digicool.com
Mild mannered software developer icq: 7127228
by day, super villain by night. phone: 519-884-2434
RE: [Zope-PTK] Upload images into ZClass based objects [ In reply to ]
>-----Original Message-----
>From: Mike Pelletier [mailto:mike@digicool.com]
>Sent: Monday, March 20, 2000 8:12 AM
>To: Chip Vanek
>Cc: zope-PTK@zope.org
>Subject: Re: [Zope-PTK] Upload images into ZClass based objects
>
>
>On Sun, 19 Mar 2000, Chip Vanek wrote:
>
>> Hi,
>>
>> Does anyone know the best way to add support for binary files
>> to the PTK?
>
> Are you unhappy with the provided Image and File PTK objects? They
>provide almost the same behaviour as the standard Zope ones. In fact,
>they extend the standard ones, but perform some 'behaviour
>modification'.

I just grabbed the latest CVS and see that you moved the DTML files
and added the image.py & file.py files. I am out of sync and using the
PTK from Mar 3rd. I will get back into the mainstream and see if those
new object meet the need. Do they store the actual file or image in
the external file system or in the ZODB?

>
>> First I would like to add support for the inclusion
>> of gif/jpeg uploads into PTK derived objects.
>
> I'm sure I am not understanding you... You want the PortalContent
>class to manage a set of images?
>

No, I just want to be able to create Portal objects that have
imbedded images as an attribute.


>> The existing Document ZClass allows for the upload of text &
>html with
>> python code like below:
>
> If you have a Document ZClass, you are using a very old PTK. There
>are no ZClass content objects presently, and haven't been since before
>IPC8...
>
I think I am just missunderstanding what a ZClass really is. I was
assuming that the object that the "*.py" files creates and is registered
in the portalobject are ZClasses.

>> It looks like manage_addImage in Image.py is closest but what is the
>> right python syntax to call this in my ZClass file?
>
> manage_addImage is inserted as a method in PortalFolder. ...Wait a
>moment, no it's not. 'addImage' (from ZopePTK/PTKBase/Image.py) is.
>Maybe we're not talking about the same thing at all. I'll
>pretend we are.
>;-)
>
I will move to the latest code and try image.py, but I think that
it still will not completely meet my needs.

> It's called on the folder you wish to add the image to.
>It could be
>used from Python like this (as an external method):
>
>def populate_folder(self, filename):
> file = open(filename).read()
> self.addImage('id', file, 'Title', 'Description of this image')
>
> (There are a couple more arguments with default values, see the
>source.)
>
Is the "filename" in the code above a path to a file local to
the Zope server or local to the users browser? I would like to
have the user "upload" a file.


>> Does anyone know a way to allow the user to browse a local
>> file using a normal <input type="file"...> button and then
>> automagically upload the file to overwrite existing or create
>> a new file outside the ZODB.
>
> I'll leave this to someone with some experience in this sort of
>thing.
>
OK

Thanks for the reply,

Chip

>Mike.
>
>--
>Mike Pelletier email: mike@digicool.com
>Mild mannered software developer icq: 7127228
>by day, super villain by night. phone: 519-884-2434
>
>
RE: [Zope-PTK] Upload images into ZClass based objects [ In reply to ]
On Mon, 20 Mar 2000, Chip Vanek wrote:

> I just grabbed the latest CVS and see that you moved the DTML files
> and added the image.py & file.py files. I am out of sync and using the
> PTK from Mar 3rd. I will get back into the mainstream and see if those
> new object meet the need. Do they store the actual file or image in
> the external file system or in the ZODB?

They store the data in the ZODB. This is unlikely to change.

> No, I just want to be able to create Portal objects that have
> imbedded images as an attribute.

Images are almost never stored as simple attributes in Zope. By
'simple attribute', I mean an attribute which is not itself a Zope
object. Given that, any Folderish object full of Image objects will look
like an object with Image attributes. Unfortunately, there is presently
no Folderish, PTK-aware object, so if you want something that is both
content and a container, you'll have to write it. Or, if your needs are
general enough, create a Tracker issue describing them and it might be
something suitable for the PTK.

> I think I am just missunderstanding what a ZClass really is. I was
> assuming that the object that the "*.py" files creates and is registered
> in the portalobject are ZClasses.

A ZClass is a class which is created entierly through-the-web. They
do not exist on the filesystem, but rather in the ZODB.
(/Control_Panel/Products/aProduct/aZClass) What the various PortalContent
classes do is make themselves available as a ZClass's base class, but they
are not ZClasses.

> I will move to the latest code and try image.py, but I think that
> it still will not completely meet my needs.

No, not if your needs include serving them from and uploading them to
the filesystem.

> >def populate_folder(self, filename):
> > file = open(filename).read()
> > self.addImage('id', file, 'Title', 'Description of this image')

> Is the "filename" in the code above a path to a file local to
> the Zope server or local to the users browser? I would like to
> have the user "upload" a file.

It is a file on the server. You can probably figure out how to
receive uploads by looking at the Image wizard and add method. The wizard
accepts uploads.

Mike.

--
Mike Pelletier email: mike@digicool.com
Mild mannered software developer icq: 7127228
by day, super villain by night. phone: 519-884-2434
RE: [Zope-PTK] Upload images into ZClass based objects [ In reply to ]
>-----Original Message-----
>From: Mike Pelletier [mailto:mike@digicool.com]
>
>On Mon, 20 Mar 2000, Chip Vanek wrote:
>
>> I just grabbed the latest CVS and see that you moved the DTML files
> and added the image.py & file.py files. I am out of sync and using
>> PTK from Mar 3rd. I will get back into the mainstream and see if those
>> new object meet the need. Do they store the actual file or image in
>> the external file system or in the ZODB?
>
> They store the data in the ZODB. This is unlikely to change.

OK, Then I will start there. Again I am just trying to avoid having
the ZODB grow too fast. Maybe I will look into the use of the PIL
lib to control the actual size of the uploaded image file and create
thumbnails. I think that the PhotoAlbum product does some of this.

>
>> No, I just want to be able to create Portal objects that have
>> imbedded images as an attribute.
>
> Images are almost never stored as simple attributes in Zope. By
>'simple attribute', I mean an attribute which is not itself a Zope
>object. Given that, any Folderish object full of Image
>objects will look
>like an object with Image attributes. Unfortunately, there is
>presently
>no Folderish, PTK-aware object, so if you want something that is both
>content and a container, you'll have to write it. Or, if your
>needs are
>general enough, create a Tracker issue describing them and it might be
>something suitable for the PTK.
>
I think that me needs are rather generic but time will tell. How
do I go about creating my own Folderish object? I need to support
the upload of MS Office files (.ppt, .doc, .xls) that may have
imbedded objects or assosiated image files. I also need to have
each file have a Zope object that controls metadata, access, and
ZCatalog indexing. That could be a simple object that served the
files from the server filesystem or a ZODB folderish object that
contains the uploaded files. WebDAV works for getting the file
up to the ZODB but I do not yet see how to trigger the metadata
collection and indexing activities. The nullresource method in
WebDAV seems to be the right place to start. In what object should
I subclass this method? Has anyone else doe this? I remember seeing
some posting on nullresource but cannot find it now?

>> I think I am just missunderstanding what a ZClass really is. I was
>> assuming that the object that the "*.py" files creates and
>is registered
>> in the portalobject are ZClasses.
>
> A ZClass is a class which is created entierly
>through-the-web. They
>do not exist on the filesystem, but rather in the ZODB.
>(/Control_Panel/Products/aProduct/aZClass) What the various
>PortalContent
>classes do is make themselves available as a ZClass's base
>class, but they
>are not ZClasses.
>
OK, that helps in understanding thinks (I think;) I am just looking
for sample code to model how to move forward. Learning is happening
it is just so painfully slow.

>> I will move to the latest code and try image.py, but I think that
>> it still will not completely meet my needs.
>
> No, not if your needs include serving them from and
>uploading them to
>the filesystem.
>
I will continue to work with JFarr to see if the LocalFS product
can link with the PTK in the longer term. I will share any successes
I have with the list.

>> >def populate_folder(self, filename):
>> > file = open(filename).read()
>> > self.addImage('id', file, 'Title', 'Description of this image')
>
>> Is the "filename" in the code above a path to a file local to
>> the Zope server or local to the users browser? I would like to
>> have the user "upload" a file.
>
> It is a file on the server. You can probably figure out how to
>receive uploads by looking at the Image wizard and add method.
> The wizard
>accepts uploads.
>
Thanks for the tips.

Chip

>Mike.
>
>--
>Mike Pelletier email: mike@digicool.com
>Mild mannered software developer icq: 7127228
>by day, super villain by night. phone: 519-884-2434
>
>