There are plenty of examples of how to upload files in Pylons, but
none of them check if the user actually put a file in the form or
not. If they don't, the application breaks. Wonderful.
So, how do you check? Well, I'd expect this to work:
if not request.params['file']:
return "No file was uploaded"
Unfortunately, even if the file is there it evaluates to falsy.
print "True" if request.params['file'] else "False" # always False
I did find a reliable way to test it though:
if request.params['file'] == u'':
return "No file was uploaded"
Yeah, it comes out as an empty string if there's no file. Weird. Is
this a good enough check? Will it still act this way when proxied to
by different servers?
I'm really surprised I couldn't find this information elsewhere.
Should we add this to the tutorials?
http://wiki.pylonshq.com/display/pylonsdocs/Form+Handling
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---