Hi,
I tried the following:
import web
urls = ('/upload', 'Upload')
class Upload:
def GET(self):
form = web.form.Form(web.form.File("myfile"))
return """<html><body>
<form method="POST" enctype="multipart/form-data" action="">
%s<input type="submit"/></form></body></html>""" % form.render()
def POST(self):
form = web.form.Form(web.form.File("myfile"))
if form.validates():
x = web.input(myfile={})
print x['myfile'].filename, len(x['myfile'].value), "bytes"
else:
print "invalid form"
raise web.seeother('/upload')
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
But I get this exception when uploading binary files:
File "/usr/lib/pymodules/python2.5/web/webapi.py", line 265, in input
return storify(out, *requireds, **defaults)
File "/usr/lib/pymodules/python2.5/web/utils.py", line 145, in storify
value = getvalue(value)
File "/usr/lib/pymodules/python2.5/web/utils.py", line 132, in getvalue
return unicodify(x.value)
File "/usr/lib/pymodules/python2.5/web/utils.py", line 127, in unicodify
if _unicode and isinstance(s, str): return safeunicode(s)
File "/usr/lib/pymodules/python2.5/web/utils.py", line 235, in safeunicode
return obj.decode(encoding)
File "/usr/lib/python2.5/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte (foo) in position (bar):
unexpected code byte
My real form is, of course, more complex, so I like to validate it.
Thanks in advance for any hint!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---