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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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?

Reply via email to