<form action="${h.url.current()}" method="POST" enctype="multipart/form-data">
<input type="file" name="your_file" />
</form>
class MyValidator(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = True
name = formencode.validators.String(not_empty=True, messages={'empty': 'Please enter your name'})
your_file = formencode.validators.FieldStorageUploadConverter(not_empty=True, messages={'empty': 'You haven\'t selected any files'})
try:
form_result = MyValidator().to_python(dict(request.params))
except formencode.Invalid as error:
return 'failed'
else:
print type(form_result['your_file'])
That's my code. form_result['your_file']
is a Unicode object. Because of this, I can't read the file or do any 'file' related tasks. The only way I've found to access it is to abandon formencode after it's performed its validation and revert to request.POST['your_file']
.
What am I doing wrong?