[Zope] - Newbie alert - how to upload multiple images at once withmanage_add_image

Casey Duncan cduncan@kaivo.com
Tue, 27 Feb 2001 09:30:41 -0700


stefano.ciccarelli@thewhitebird.com wrote:
> 
> HI,
> I am trying to set up a form when a user can upload three images at
> once: one for a logo, one for a city map and one for a country map.
> 
> These images are used by a ZClass (Base classes: ZCatalog Aware, Object
> Manager) to display a hotel web page, with info about this hotel.
> 
> Authorised users are supposed to create this hotel instance.
> 
> I created a Hotel_add_form:
> 
> <HTML>
> <BODY>
> 
> <p><h2>Here you can upload hotel logo and maps into the hotel
> file.</h2></p>
> 
> <form action="map_add" method="post"
> enctype="multipart/form-data">
> <p><b>Logo</b></p>
> <input type="hidden" name="logo_id" value="logo26">
> <p>Title: <input type="text" name="logo_title"> </p>
> <p>File: <input type="file" name="file"></p><br>
> <p><b>City map</b></p>
> <input type="hidden" name="citymap_id" value="map26">
> <p>Title: <input type="text" name="citymap_title"> </p>
> <p>File: <input type="file" name="file"></p><br>
> 
> <input type="submit">
> </form>
> </BODY>
> </HTML>
> 
> and a method map_add
> 
> <dtml-call
>   expr="manage_addImage(
>     id=logo_id, file=file, title=logo_title)">
> 
> <dtml-call
>   expr="manage_addImage(
>     id=citymap_id, file=file, title=citymap_title)">
> 
> <p>Thanks for your photo submission.</p>
> 
> Unfortunately when I try to use it I get the following error:
> 
> Zope Error
> Zope has encountered an error while publishing this resource.
> 
> Error Type: AttributeError
> Error Value: seek
> 
[snip]

For one, both file form input boxes are named "file". Try naming them
"logo_file" and "citymap_file".

You could also use records marsalling to eliminate the redundant coding
both on the form and map_add: (Not tested)

<form action="map_add" method="post" enctype="multipart/form-data">
<dtml-in expr="['Logo', 'Map']">
<p><b><dtml-var sequence-item></b></p>
<input type="hidden" name="images.id:records" value="<dtml-var
expr="some expr">">
<p>Title: <input type="text" name="images.title:records"> </p>
<p>File: <input type="file" name="images.file:records"></p><br>
</dtml-in>
</form>

Then map_add could be:

<dtml-in images>
	<dtml-call expr="manage_addImage(id, file, title)">
</dtml-in>

or a python script:

for img in context.REQUEST['images']:
	context.manage_addImage(img.id, img.file, img.title)

hth
-- 
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>