[Zope] how to upload a batch of files????

Dieter Maurer dieter@handshake.de
Sat, 1 Sep 2001 23:45:26 +0200 (CEST)


Trevor Toenjes writes:
 > This is a great request.  I am facing this problem as well, except with
 > images. I went with the one-at-a-time approach using "manage_addImage".
 > 
 > I would like to upload several images into a folder/zClass,etc. from a
 > single form.
 > image1    [BROWSE]
 > image2    [BROWSE]
 > image3    [BROWSE]
 > [ADD]
 > 
 > My guess is that there needs to be some logic and recursion over the form to
 > submit each image(or file) separately to "manage_addImage".
You problem is much easier....

Use a special naming convention for your file upload controls,
say all have suffix '__'. Then, in the form action, you iterate
over the form variables.

Python Script:

     r= container.REQUEST

     for k,v in r.form.items():
       if k[-2:] == '__':
         # an image
	 if v.filename:
	   # it's not empty
	   context.manage_addImage(chooseId(k),v)


Dieter