On Friday, October 28, 2011 12:37:04 PM UTC-4, Ross Peoples wrote:
>
> The list part was a typo, because the controller was just an example. I 
> found the original thread where I got the store() code from:
>
>
> https://groups.google.com/forum/#!searchin/web2py/manual$20upload/web2py/a5YanKxNbVU/99bxaB7A82IJ
>
> See Massimo's first reply.
>

Massimo made an error in his first reply (request.vars.image) and corrected 
it in his second reply (request.vars.image.file).
 

> Also see this thread, because this person seems to have the same problem, 
> but couldn't figure it out:
>
>
> https://groups.google.com/forum/#!searchin/web2py/manual$20upload/web2py/xmy5J6XaUuk/TWmZSo6SLUcJ
>

Yes, he made the same mistake, using request.vars.file (the FieldStorage 
object), instead of request.vars.file.file (the file object).
 

> As far as I can tell, nothing calls store(file). The only thing in web2py 
> that calls it, passes the filename in addition to the file. And since you 
> cannot make store() work at all without giving it a filename...
>

store() works without passing it a filename -- if no filename is provided, 
it uses file.name as the filename.

Anyway, it might not be a bad idea to let store() take a FieldStorage 
object, though maybe with code that specifically checks for FieldStorage 
(this would replace lines 3-4 of the current function):

if isinstance(file, cgi.FieldStorage):
    file = file.file
    filename = filename or file.filename
elif not filename:
    filename = file.name

Anthony

Reply via email to