Why not use the web2py way... in controller
form=crud.create(db.page) return dict(form=form) and in view {{=form}} You code does not work because: - request.vars.file contains a cgi.FieldStorage object and you cannot put that id the database - the the actual file has to be streamed in, safely renamed to avoid directory traversals, stored on file, the name only goes in the database - you use form.vars.id. That is only created by web2py after calling the form.accepts function, i.e. after insert. On Jun 11, 3:28 am, Kenneth <kenneth.t.lundst...@gmail.com> wrote: > Hello, > > in my application there is a need for users to add there own pages and > an a page you should be able to upload files (Word, Excel), multiple > files. > > So instead of defining "Field('picture','upload',default=''))" in my > page table I made a own table just for the files. > > First I didn´t have the file uploading feature so the form to make a > new page is made with "form = SQLFORM(db.page, ....." > > To get the upload file option when creating the page I put > <tr> > <td><input type="text" name="file_desc" /></td> > <td><input class="upload" id="page_file" name="page_file" > type="file" /></td> > </tr> > > and > if (request.vars.page_file != ""): > page_file_id = db.page_files.insert( > file = request.vars.page_file, > description = request.vars.file_desc, > page = form.vars.id) > > This doesn´t work, the database i populate but wrongly I think. > > The problem is I think in the HTML code. > > When reading the examples I found this text: "Remember the > upload=URL(...'download'...) statement in the register_dog function.", > but when reading the register_dog function I couldn´t find the > statement. > > Any exemples how to do this? > > Kenneth