Works great. Thx!

On Sep 12, 11:26 am, mdipierro <[email protected]> wrote:
> You should be able to just do
>
>   infile=os.path.join(request.folder,'static/x/y.mp3')
>   db.audio.insert(
>       book=row.queue.book,
>       name=db.audio.name.store(open(infile,'rb'),'dummy.mp3')
>       )
>
> store uses shutil.copyfileobj  inside
>
> On Sep 12, 10:09 am, weheh <[email protected]> wrote:
>
> > I have a pre-existing file, static/x/y.mp3, that I want to copy to an
> > upload record.
>
> > # model
> > db.define_table('audio',
> >   Field('name','upload',length=50,label=T('Upload
> > file'),autodelete=True,
> >     uploadfolder=os.path.join(request.folder,'static/audio'),
> >     uploadseparate=True,
> >     requires=IS_UPLOAD_FILENAME(extension='mp3'),
> >     )
> >   )
>
> > I want to use shutil.copyfileobj to do the copying since the audio
> > file is very large. What would the syntax be to insert a new record
> > into the audio table using shutil.copyfileobj? In particular, I don't
> > understand what the destination file should be?
>
> > p.s.
> > I had tried using cStringIO, but that didn't work -- the stored file
> > was empty:
>
> >   infile=os.path.join(request.folder,'static/x/y.mp3')
> >   stream=cStringIO.StringIO()
> >   stream.write(open(infile,'rb').read())
> >   db.audio.insert(
> >       book=row.queue.book,
> >       name=db.audio.name.store(stream,'dummy.mp3')
> >       )
>
> > Anyway, cStringIO is not the way to go. The file to be copied is too
> > large.
>
> > Thanks.
>
>

Reply via email to