[Zope] Strange error with Photo Product
Dennis Allison
allison@sumeru.stanford.EDU
Mon, 15 Jul 2002 18:51:01 -0700
>
>Dennis Allison writes:
> > ...
> > container.manage_addProduct.manage_addPhoto(id,title,file,.. )
> > ...
> > Zope Error
> > Zope has encountered an error while publishing this resource.
> > Error Type: KeyError
> > Error Value: the_file
> >
> > ...
> >
> > File /var/zope/lib/python/Products/PythonScripts/PythonScript.py, line
> > 302, in _exec
> > (Object: photo_upload)
> > (Info: ({'script': <PythonScript instance at 8b70a88>, 'context':
> > <Folder instance at 8d91b60>, 'container': <Folder instance at 8d91b60>,
> > 'traverse_subpath': []}, (), {}, None))
> > File Script (Python), line 8, in photo_upload
> > File /var/zope/lib/python/AccessControl/ZopeGuards.py, line 90, in
> > guarded_getitem
> > File /var/zope/lib/python/ZPublisher/HTTPRequest.py, line 847, in
> > __getitem__
> > KeyError: (see above) File
>Apparently, your "file" in not a "ZPublisher.HTTPRequest.FileUpload"
>instance. --Dieter
That's what I would have guessed, but when I examine it on arrival to the
form that contains the call
container.manage_addProduct.manage_addPhoto(id,title,file,.. )
it is of FileUpload type. Moreover it gets installed in the PhotoFolder
correctly. The particular code is neither long nor complex. I've reproduced
it below.
The form, a DTML-Method:
------------------------------------------------------------------------
<dtml-var standard_html_header>
<p>
<form action="photo_upload" method="POST" enctype="multipart/form-data">
<input type="file" name="the_file" size="30">
<br>
<input type=submit name=submit value="Upload Photo">
</form>
<p>
<dtml-var standard_html_footer>
------------------------------------------------------------------------
The handler, a Python Script:
------------------------------------------------------------------------
request = container.REQUEST
RESPONSE = request.RESPONSE
# move to photofolder
p = container.restrictedTraverse('Photos')
if( not p ): raise AssertionError, 'No Place to store Photos'
the_id = container.genUID()
the_title = 'My Photo'
the_file = request['the_file']
p.manage_addProduct['Photo'].manage_addPhoto( the_id, the_title, the_file, engine='PNG')
request['RESPONSE'].redirect( request['URL'] )
------------------------------------------------------------------------
Photos is a PhotoFolder instance, essentially a vanilla instance out
of the box without much of anything set. genUID is a Python external
method that produces a unique identifier. PNG is installed and functions
appears to function properly.
Any suggestions/pointer appreciate. This one's got me stumpped.
-dra