[mod_python] File upload - AttributeError using the FieldStorage object

Robert Synnott rsynnott at gmail.com
Fri Jun 30 15:33:30 EDT 2006


On 6/30/06, Thomas J. Schirripa <tommys at eden.rutgers.edu> wrote:
> Before stating my problem, let me say that I am running apache version 2.0.52, mod_python 3.2.8, python 2.3, all on Redhat Enterprise Linux WS release 4.
>
> I am new to mod_python and even python itself, but I am trying to upload a file and it's not working. Right now I wanted to write a practice program that just dumps the text in the file to a webpage, but eventually I would like to manipulate the data in the file someway and output something different. I am certain my html is fine... I have:
> <form action='upload.py' method='post' enctype='multipart/form-data'>
>         <input type='file' name='input_file'><br><br>
>         <input type='submit'>
> </form>
>
> Originally I tried using the publisher handler, so my "action" was pointing to a different file and method that handles the request. To access the FieldStorage object I used req.form. But to correspond to the html above, I made "upload" my PythonHandler and created my own FieldStorage object as follows:
>
> def handler(req):
>     fields = util.FieldStorage(req)
>     f = fields['input_file']
>
> >From my understanding, the variable "f" should contain a Field object, NOT a FieldString as I am getting. So when I say f.file or f.filename, an AttributeError is raised because (of course) a FieldString does not have the attributes file or filename.
>
> I looked around a lot online, but this seems to be an old problem with earlier versions of mod_python, but I am running 3.2.8. Could there still be a problem witht the __getitem__ method or the FieldStorage not being able to recognize the mime type (although the documentation states this problem has been fixed).
>
> Help would be much appreciated, so thanks in advance
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>

f.data, I think.
Rob


More information about the Mod_python mailing list