I will try this. How about how to open the upload file during validation (see my previous post)?
On Jun 16, 2:58 am, mdipierro <mdipie...@cs.depaul.edu> wrote: > Try this: > > file_form=SQLFORM.factory(db.auth_user,db.othertable,db.srcfile) > ... > if FORM.accepts(file_form,request.vars,formname='file_form'): # no > upload > > check_file_in(file_form) # same as onvalidation > > if not file_form.errors: > db.srcfile.insert( > name=db.srcfile.name.store( > request.vars.name.file,request.vars.name.filename), > ) > > On Jun 16, 1:29 am, weheh <richard_gor...@verizon.net> wrote: > > > I don't think this will work since my factory is using multiple > > tables. > > > I don't mean to digress, but another question is, how to open the file > > during the onvalidation? I need to open the file and read it in to > > check the contents for stuff that will determine whether it's valid or > > not. I've tried: > > > text=URL(r=request,c='default',f='download',args=form.vars.name) > > > I've also tried > > > text=open(os.path.join(request.folder,'uploads',form.vars.name),'rb').read() > > > and other variations, but so far, can't seem to get it to work. > > > On Jun 16, 2:17 am, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > aha, you can do this > > > > file_form=SQLFORM.factory(....,table_name='srcfile') > > > file_form.accepts(request.vars,formname='file_form',onvalidation=check_file_in): > > > db.srcfile.insert(name=form.vars.name) > > > > On Jun 16, 12:34 am, weheh <richard_gor...@verizon.net> wrote: > > > > > Nice and simple. Thanks Massimo. > > > > > But FWIW, this doesn't rename the no_table.name.blahblah.txt file to > > > > srcfile_table.name.blahblah.txt, which may or may not be the right > > > > thing to do -- I'm not sure. Since I am uploading everything through > > > > the factory form, all fields are no_table fields. Since I eventually > > > > store them in their respective tables, it seems logical that they go > > > > into the corresponding (correctly named) folder/filenames -- > > > > srcfile_table/ab/srcfile_table.name.blahblah.txt. What do you think? > > > > > On Jun 15, 11:46 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > > > Actually this would work but it is not the best way, ... the problem > > > > > is that the storage is already performed by accepts so you must do > > > > > simply > > > > > > file_form.accepts(request.vars,formname='file_form',onvalidation=check_file_in): > > > > > db.srcfile.insert(name=form.vars.name) > > > > > > On Jun 15, 10:44 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > > > > May be a bug. can you try? > > > > > > > file_form.accepts(request.vars,formname='file_form',onvalidation=check_file_in): > > > > > > request.vars.name.file.seek(0) ### add this line > > > > > > db.srcfile.insert( > > > > > > name=db.srcfile.name.store( > > > > > > request.vars.name.file,request.vars.name.filename), > > > > > > ) > > > > > > > On Jun 15, 11:02 am, weheh <richard_gor...@verizon.net> wrote: > > > > > > > > # model > > > > > > > db.define_table('srcfile', > > > > > > > Field('name','upload',length=50,label=T('Upload > > > > > > > file'),autodelete=True, > > > > > > > uploadseparate=True, > > > > > > > requires=( > > > > > > > > > > > > > > IS_UPLOAD_FILENAME(extension='pdf|txt|doc|htm|html|xml|ppt'), > > > > > > > IS_LENGTH(5000000,10)) > > > > > > > ), > > > > > > > ) > > > > > > > > # controller > > > > > > > ... > > > > > > > file_form=SQLFORM.factory(db.auth_user,db.othertable,db.srcfile) > > > > > > > ... > > > > > > > if > > > > > > > file_form.accepts(request.vars,formname='file_form',onvalidation=check_file_in): > > > > > > > db.srcfile.insert( > > > > > > > name=db.srcfile.name.store( > > > > > > > request.vars.name.file,request.vars.name.filename), > > > > > > > ) > > > > > > > ... > > > > > > > > Problem is, file gets uploaded into > > > > > > > no_table.name/a2/ > > > > > > > no_table.name.a24060930d31d0c1.313234363931322e747874.txt > > > > > > > prior to the insert. After the insert, there is a folder > > > > > > > srcfile.name/b1/srcfile.name.b192a5e35dc5081e. > > > > > > > 313234363931322e747874.txt > > > > > > > except that the file is empty. > > > > > > > > Question: is this a bug, or do I need to explicitly copy from the > > > > > > > source to the destination? If the latter, what would the > > > > > > > rationale be > > > > > > > for creating the destination file without copying the contents > > > > > > > from > > > > > > > the source?