Final solution was this: _tables.py def store_file(file, filename=None, path=None): path = path #"applications/init/uploads" if not os.path.exists(path): os.makedirs(path) pathfilename = os.path.join(path, filename) dest_file = open(pathfilename, 'wb') try: shutil.copyfileobj(file, dest_file) finally: dest_file.close() return filename
## Repository db.define_table('repository', Field('name', type='string'), Field('directory', default='applications/init/uploads'), Field('priority', 'integer', default=100), format='%(name)s') ## File - Files stored in the repository db.define_table('workbench', Field('repository', 'reference repository'), Field('name') Field('workbench', type='upload', required=True, custom_store=store_file , custom_retrieve=retrieve_file), # Field('sequence', 'integer', required=True), Field('created_date', 'datetime', default=request.now, readable=False, writable=False), Field('modified_date', 'datetime', update=request.now, readable=False, writable=False), format='%(name)s') Repository.py def onvalidation(form): repository = db.repository(form.vars.repository) if repository is None: raise HTTP(404) db.workbench.workbench.uploadfolder = repository.directory def oncreate(form): db(db.workbench.id==form.vars.id).update(name=form.vars.workbench) def onupdate(form): db(db.workbench.id==form.vars.id).update(name=form.vars.workbench) def index(): """ Additional code here """ form = SQLFORM.smartgrid(db.repository, fields=fields, orderby=orderby, searchable=True, details=details, editable=editable, deletable=deletable, oncreate=oncreate, onupdate=onupdate, onvalidation=onvalidation, links=links, paginate=paginate, linked_tables=linked_tables) return dict(form=form) Need to use onvalidation to set the upload directory, oncreate is executed after the record is created. -- 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.