[mod_python] file uploads and StringField / Field instances

David Fraser davidf at sjsoft.com
Sat Mar 13 22:02:34 EST 2004


Volodya wrote:

>Hello,
>
>I'm experimenting with form-based file uploads (mod_python.publisher
>handler). After reading mod_python-docs, i expect to get an instance of
>Field class in one of req.form's items. But i always get StringField
>instance. 
>  
>
I reported this problem on the python-dev list.
Here is my mail... and I have attached the patch... try it out and 
report back...
David Fraser wrote:

> Hi
>
> Submitting a file through a form (multipart/form-data) that has worked 
> under mod_python 3.0.3 (ended up as a File object) seems to produce a 
> StringField under mod_python 3.1.3
>
> It seems this part of the diff is responsible (util.py):
>
> @@ -260,10 +224,10 @@
>         found = []
>         for item in self.list:
>             if item.name == key:
> -                if isinstance(item.file, StringIO.StringIO):
> -                    found.append(StringField(item.value))
> -                else:
> +                if isinstance(item.file, FileType):
>                     found.append(item)
> +                else:
> +                    found.append(StringField(item.value))
>         if not found:
>             raise KeyError, key
>         if len(found) == 1:
>
> Since in mod_python 3.1.3 the file is created using tempfile, 
> item.file can end up being a tempfile._TemporaryFileWrapper. This does 
> in fact happen (at least under Windows), resulting in the attachment 
> coming out as a StringField.
>
> This patch fixes the problem by checking if the file has a "file" 
> attribute itself, and checking the type of that.
> There may be a cleaner way to do it.
>
> David


-------------- next part --------------
A non-text attachment was scrubbed...
Name: util-tempfilefix.patch
Type: text/x-patch
Size: 1476 bytes
Desc: not available
Url : http://mailman.modpython.org/pipermail/mod_python/attachments/20040313/3f7accea/util-tempfilefix.bin


More information about the Mod_python mailing list