[Zope] stupid file upload question

Joh Johannsen jojo@farm9.com
Thu, 14 Dec 2000 15:03:21 -0800


Dieter Maurer wrote:

> Joh Johannsen writes:
>  > What sort of object is this "REQUEST.form['attached_file']"?   Is there some
>  > way to find out this sort of thing when you have a Python object?  (I'm new
>  > to Python)
> It is a "ZPublisher.HTTPRequest.FileUpload" object.
> >From its (source) documentation:
>
>     File upload objects are used to represent file-uploaded data.
>
>     File upload objects can be used just like files.
>
>     In addition, they have a 'headers' attribute that is a dictionary
>     containing the file-upload headers, and a 'filename' attribute
>     containing the name of the uploaded file.
>
>  > Is that even the place to look to get the name of the file on the server
>  > after it is uploaded?
> You should not rely on the fact that the data is stored somewhere
> on the server.
>
>  > That's why I mentioned the quote from that How-To (which the above is
>  > basically a copy of):  "In you python external method you can now reference
>  > REQUEST.form['attached_file'] as a normal file. You can perform things such
>  > as read() on the object. "
> "REQUEST.form['attached_file']" should be a "FileUpload" object
> and as such have a "read" method (beside many others).
>
> Thus, "REQUEST.form['attached_file'].read()" should return the
> file content.
>
> In an earlier message, you said, it did not.
> What happened?
>

What happens is that if I have this:


def get_file_name(self,REQUEST):
    s = REQUEST.form['attached_file'].filename
    contents = REQUEST.form['attached_file'].read()
    return s

I get a Zope error for the External Method, when I reload it by clicking on "edit"
Here is traceback...

Traceback (innermost last):
  File /usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py, line 222, in
publish_module
  File /usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py, line 187, in
publish
  File /usr/local/Zope-2.2.0-src/lib/python/Zope/__init__.py, line 221, in
zpublisher_exception_hook
    (Object: get_file_name)
  File /usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py, line 171, in
publish
  File /usr/local/Zope-2.2.0-src/lib/python/ZPublisher/mapply.py, line 160, in
mapply
    (Object: manage_edit)
  File /usr/local/Zope-2.2.0-src/lib/python/ZPublisher/Publish.py, line 112, in
call_object
    (Object: manage_edit)
  File
/usr/local/Zope-2.2.0-src/lib/python/Products/ExternalMethod/ExternalMethod.py,
line 201, in manage_edit
    (Object: get_file_name)
  File
/usr/local/Zope-2.2.0-src/lib/python/Products/ExternalMethod/ExternalMethod.py,
line 210, in getFunction
    (Object: get_file_name)
  File /usr/local/Zope-2.2.0-src/lib/python/App/Extensions.py, line 217, in
getObject
    (Info: ('/usr/local/Zope2/Extensions/get_file_name.py', 'get_file_name'))
SyntaxError: (see above)


JJ