detailed examples are for hard things AND people not willing to experiment :-P
it's pretty simple. Given a table with Field('contents', 'upload') any submitted form will have "contents" as a FieldStorage (standard wsgi behaviour). The real deal (or, "the nifty trick") is checking BEFORE form.process().accepted (if you're not using your own form, which should have been more fun ;-)) what is coming along....... So, you add Field('contents_size', 'integer') Field('contents_filename', length=512) and you'd like to store the file size and the original filename.... Any piece of code happening AFTER form.process().accepted for a SQLFORM have done already the insertion at the database level. So you must intercept what you need just before it. SQLFORM won't hide contents_size and contents_filename by default, so the other piece of the nifty trick is remembering that you should set them as hidden by setting writable=False on them. >From there on, it's pretty easy. form = SQLFORM(db.tablename) filesize_ = len(request.vars.contents.value) filename_ = request.vars.contents.filename form.vars.contents_size = filesize_ form.vars.contents_filename = filename_ if form.process().accepted: blablabla On Wednesday, January 13, 2016 at 7:22:19 PM UTC+1, Alex Glaros wrote: > > am having trouble finding detailed examples. Can you please help with > syntax? > > Am determining size when uploading a user's photo (thumbnail) to their > profile: > > if form.process().accepted: > session.flash = 'profile update accepted' > file_info = cgi.FieldStorage(form.vars.thumbnail) > form.vars.file_size = len(file_info) > > the goal is to populate field file_size with number of bytes the file > contains > > but the above raises errors > > thanks > > Alex > -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.