[mod_python] upload file?

Maxime Yve maxime.yve at unilog.fr
Thu May 6 19:49:29 EST 2004


Hi,

 

I have the same problem with mod_python 3.1.3 on windows:

This comes from the __getitem__ method of FieldStorage

 

Indeed => :

On windows

 

>>> import tempfile

>>> glop = tempfile.TemporaryFile('w+b')

>>> type(glop)

      <type 'instance'>

 

On Unix :

>>> import tempfile

>>> glop = tempfile.TemporaryFile('w+b')

>>> type(glop)

      <type 'file'>

 

And isinstance(item.file, FileType) return false on Windows, this cause the
bug on __getitem__

 

To correct temporary this problem (I'm not active on the community and I
can't correct the mistake)

You can do this monkey hook on your own file before using FieldStorage:

 

from types import *

from mod_python.util import StringField

 

 

# patch bug on windows for mod_python 3.1.3

def patch_getitem(self, key):

      """Dictionary style indexing."""

      if self.list is None:

            raise TypeError, "not indexable"

      found = []

      for item in self.list:

            if item.name == key:

                  if isinstance(item.file, FileType) or
isinstance(item.file, InstanceType):

                        found.append(item)

                  else:

                        found.append(StringField(item.value))

      if not found:

            raise KeyError, key

      if len(found) == 1:

            return found[0]

      else:

            return found

util.FieldStorage.__getitem__ = patch_getitem

 

Max

 

-----Original Message-----
From: mod_python-bounces at modpython.org
[mailto:mod_python-bounces at modpython.org] On Behalf Of John Mudd
Sent: jeudi 6 mai 2004 19:21
To: mod_python at modpython.org
Subject: [mod_python] upload file?

 

(Sorry if you see this msg twice.  I submitted this earlier today by under a
non-member email address.)

 

I'm trying to upload a file.  I specified a "file" type input field in my
HTML, it displays as expected with the "Browse..." button, I'm able to
select a file but...

 

When I look in the FieldStorage dictionary for the field I only get a String
type field that is the file name.  I was expecting a "Field" type object
that would provide access to the file name and contents.

 

What am I missing? 

 

John

_______________________________________________

Mod_python mailing list

Mod_python at modpython.org

http://mailman.modpython.org/mailman/listinfo/mod_python

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.modpython.org/pipermail/mod_python/attachments/20040506/2ac41b82/attachment.html


More information about the Mod_python mailing list