3

I want to create a simple file upload form and I must be completely incapable. I've read docs and tutorials,but for some reason, I'm not getting the submitted form data. I wrote the smallest amount of code I could to test and it still isn't working. Any ideas what's wrong?

def index():
    html = '''
    <html>
      <body>
      <form id="fileUpload" action="./result" method="post">
        <input type="file" id="file"/>
        <input type="submit" value="Upload"/>
      </form>
      </body>
    </html>
    '''
    return html

def result(req):
    try: tmpfile = req.form['file']
    except:
        return "no file!"
jfs
  • 399,953
  • 195
  • 994
  • 1,670
scottm
  • 27,829
  • 22
  • 107
  • 159
  • Are you using web2py framework? – jfs Mar 12 '09 at 20:24
  • What does "not working" mean? Do you have an error trace? Also, why aren't you using mod_wsgi? – S.Lott Mar 12 '09 at 21:10
  • @S.Lott "I'm not getting the submitted form data." I don't know about wsgi. – scottm Mar 12 '09 at 21:18
  • @scotty2012: "not getting" -- what does that mean? Traceback? Silence? 404 error? 500 error? See http://code.google.com/p/modwsgi/ for a better interface than mod_python. – S.Lott Mar 12 '09 at 21:32

1 Answers1

1

try putting enctype="multipart/form-data" in your form tag. Your mistake is not really mod_python related.

Vasil
  • 36,468
  • 26
  • 90
  • 114
  • that's was the problem. I went back and looked at the mod_python docs and their example doesn't have that tag. – scottm Mar 12 '09 at 22:27