Note, cgi.FieldStorage is part of the Python standard library, so we cannot
change it.
Anthony
On Thursday, May 30, 2013 5:06:20 AM UTC-4, Joe Barnhart wrote:
>
> I've had the most awful time trying to get the actual filename of an
> uploaded file to appear in my database. I've gone over and over the
> advice, but it has never worked for me. I was beginning to suspect evil
> spirits in my code when I ran across the problem...
>
> cgi.FieldStorage does NOT behave like other Python variables in that it
> doesn't resolve to True if the object contains data. It resolves to False
> ALL THE TIME, whether it has data or not.
>
> I was dutifully following advice and had code that looked like:
>
>
> if request.vars.upload:
> form.vars.filename = request.vars.upload.filename
>
>
> But guess what? The code inside "if" NEVER RUNS.
>
> For now I've worked around it by using the method "has_key()" on the
> cgi.FieldStorage object:
>
>
> if request.vars.has_key('upload'):
> form.vars.filename = request.vars.upload.filename
>
>
>
> And this works.
>
> The "proper" fix is probably to modify cgi.FieldStorage so that is
> resolves to True if it has data and False if empty, like all other Python
> objects. But I thought I'd pass along my epiphany in case others are
> wondering if their code is inhabited by evil spirits.
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.