Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I upload a file with mod_python?

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!"
like image 352
scottm Avatar asked May 19 '26 00:05

scottm


1 Answers

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

like image 153
Vasil Avatar answered May 21 '26 14:05

Vasil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!