upload file with cgi

Petteri pepper at xcs.tut.fi
Tue Jul 27 08:27:00 EDT 1999


Hi,

This must be a FAQ question, but I'm wondering where the file disappears
from FieldStorage? My own cgi-upload script used to work but now what
happens is that the FieldStorage is empty. Is this just some silly mistake
or does it have something to do with netscape?

<FORM ACTION="/cgi-bin/upload.py" method=POST enctype=multipart/form-data>
<p>Upload a file!</p>
<SELECT NAME=dest>
<OPTION value=koulutus selected>koulutus
<OPTION VALUE=tiedotus>tiedotus
</SELECT>
<INPUT TYPE="file" name="userfile" SIZE="30">
<INPUT TYPE=SUBMIT value=SEND!>
</FORM>


An excerpt from the script:

        form = cgi.FieldStorage()
        print form
        sys.stdout.flush()
        fileitem = form['userfile']
        if fileitem.file and form.has_key('dest'):
            Upload(fileitem, form['dest'].value)

and what 'print form' prints if I send the form with a file selected:
FieldStorage(None, None, [])

and, of course, an exception is raised
Traceback (innermost last): File "/usr/lib/cgi-bin/upload.py", line 53, in
Main fileitem = form['userfile'] File"/usr/lib/python1.5/cgi.py", line 907,
in __getitem__ raise KeyError, key KeyError: userfile

I'm confused. Please help.

Sami





More information about the Python-list mailing list