At onvalidation the file is "inside" the form as cStringIO.StringO
instance.  Specifically: form.vars.{{upload_fieldname}}.file.

You can get the contents like this:

contents = form.vars.{{upload_fieldname}}.file.getvalue()

It is then up to you to throw an error (or not as the case may be) with
form.errors.{{upload_fieldname}}.

There's a nice example here:
https://groups.google.com/d/msg/web2py/bu6Q-8slNII/pE3tKOAxjlYJ




On Thu, Nov 7, 2013 at 5:53 AM, weheh <[email protected]> wrote:

> I'm doing a file upload using SQLFORM and a field of type upload. I want
> to intercept the file during onvalidation and do some file manipulation
> before saving. While in the onvalidation routine I can see the original
> filename and form.vars.filename.file, which I can read.
>
> I'm wondering whether web2py has already created a file on the server by
> this point (in the onvalidation validation routine and before the
> form.process(onvalidation=myvalidation).accepted step)? If so, I'd like to
> get that file name at that time (during the validation step). Anybody know
> where I can find it?
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> 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.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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.

Reply via email to