It works! Thanks. Question, now I need to create a controller to
download the files?
I will try to add a few lines to locally remove the file once is
uploaded. I wanted to try this and perhaps to be able to fully use it
in a future. After trying SO MANY CMS systems, I found out that one of
the hardest features to find on a CMS is the ability to do sort of
this. Plone has it but it Plone covers so much that many features are
useless.  Thanks again!



On Apr 25, 8:33 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> My bad again. Try this:
>
> @auth.requires_login()
> def list_of_files():
>     import os
>     path='/upload/Documents'
>     files = os.listdir(path)
>     db.document.scandoc.uploadfolder='/upload/Documents'
>     for filename in files:
>         stream=open(os.path.join(path,filename),'rb')
>
> db.document.insert(scandoc=db.document.scandoc.store(stream,filename=filename))
>
> storedfiles=db(db.document.id>0).select(orderby=db.document.scandoc)
>     return dict(storedfiles=storedfiles,form=form)
>
> On Apr 25, 7:23 pm, greenpoise <danel.sega...@gmail.com> wrote:
>
> > Thanks! you make it look so easy!
> > From the error message below, it goes through the files but it stops.
>
> > File "/home/danel/Applications/web2py/applications/madra_v2/
> > controllers/default.py", line 198, in list_of_files
> >     stream=open(filename,'rb')
> > IOError: [Errno 2] No such file or directory: 'E37048.pdf'
>
> > On Apr 25, 7:38 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > @auth.requires_login()
> > > def list_of_files():
> > >     import os
> > >     files = os.listdir('/upload/Documents')
> > >     db.document.scandoc.uploadfolder='/upload/Documents'
> > >     for filename in files:
> > >         stream=open(filename,'rb')
>
> > > db.document.insert(scandoc=db.document.scandoc.store(stream,filename=filename))
>
> > > storedfiles=db(db.document.id>0).select(orderby=db.document.scandoc)
> > >     return dict(storedfiles=storedfiles,form=form)
>
> > > On Apr 25, 5:56 pm, greenpoise <danel.sega...@gmail.com> wrote:
>
> > > > Ok. I have tried all the above but keeps breaking for me. This is what
> > > > I am trying:
>
> > > > 1. Upload files that are already in a folder into the database
> > > > (without selecting them one by one)
> > > > 2. Display those files and be able to download them.
>
> > > > This is my code:
>
> > > > @auth.requires_login()
> > > > def list_of_files():
> > > >     import os
> > > >     files = os.listdir('/upload/Documents')
>
> > > > storedfiles=db(db.document.id>0).select(orderby=db.document.scandoc)
> > > >     db.document.scandoc.uploadfolder='/upload/Documents'
>
> > > >     for files in files:
> > > >         db.document.insert(scandoc =
> > > > db.document.scandoc.store(stream,filename=files))
> > > >     return dict(storedfiles=storedfiles,form=form)
>
> > > > and I get this error message:
>
> > > >   File "/home/danel/Applications/web2py/applications/madra_v2/
> > > > controllers/default.py", line 200, in list_of_files
> > > >     db.document.insert(scandoc =
> > > > db.document.scandoc.store(stream,filename=files))
> > > > NameError: global name 'stream' is not defined
>
> > > > Thanks in advance
>
> > > > On Apr 23, 5:34 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > > yes, you have to set
>
> > > > > db.workspace.filefield.uploadefolder='/somewhere/'
>
> > > > > On Apr 23, 2:40 pm, greenpoise <danel.sega...@gmail.com> wrote:
>
> > > > > > Is this possible? to put on db the files of a folder?
>
> > > > > > def list_of_files():
> > > > > >     import os
>
> > > > > > storedfiles=db(db.workspace.id>0).select(orderby=db.workspace.droppedfile)
> > > > > >     files = os.listdir('/home/dan/Docs')
> > > > > >     for files in files:
> > > > > >         db.workspace.insert(filefield =
> > > > > > db.workspace.droppedfile.store(files,filename='test.pdf'))
> > > > > >     return dict(storedfiles=storedfiles,form=form)
>
> > > > > > On Apr 22, 8:48 pm, greenpoise <danel.sega...@gmail.com> wrote:
>
> > > > > > > Perfect. Will try. Thanks again!
>
> > > > > > > Dan
>
> > > > > > > On Apr 22, 4:51 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > > > > > Most of it is done in the Field.store() method in sql.py. In 
> > > > > > > > fact you
> > > > > > > > can do
>
> > > > > > > > db.mytable.insert(filefield=db.mytable.filefield.store(stream,filename='ori­ginal_filename.txt'))
>
> > > > > > > > On Apr 22, 3:27 pm, greenpoise <danel.sega...@gmail.com> wrote:
>
> > > > > > > > > wow thats rough!! over 3,000 lines of coding.  thanks!!   :-)
>
> > > > > > > > > On Apr 22, 4:07 pm, Thadeus Burgess <thade...@thadeusb.com> 
> > > > > > > > > wrote:
>
> > > > > > > > > > Take a look at welcome/controllers/default.py->def download
>
> > > > > > > > > > Andhttp://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#291
>
> > > > > > > > > > Andhttp://code.google.com/p/web2py/source/browse/gluon/sql.py#2667
>
> > > > > > > > > > Andhttp://code.google.com/p/web2py/source/browse/gluon/sql.py#2694
>
> > > > > > > > > > Andhttp://code.google.com/p/web2py/source/browse/gluon/sql.py#3292
>
> > > > > > > > > > I think there are a couple more locations too... 
> > > > > > > > > > specifically web2py
> > > > > > > > > > will rename the file to something safe....
>
> > > > > > > > > > --
> > > > > > > > > > Thadeus
>
> > > > > > > > > > On Thu, Apr 22, 2010 at 2:54 PM, greenpoise 
> > > > > > > > > > <danel.sega...@gmail.com> wrote:
> > > > > > > > > > > My question is, which controller takes careof the upload 
> > > > > > > > > > > field in
> > > > > > > > > > > web2py???  Web2py makes it easy to upload a file but I 
> > > > > > > > > > > want to know
> > > > > > > > > > > how it does it so I can write a function based on it.
>
> > > > > > > > > > > Thanks
>
> > > > > > > > > > > dan
>
> > > > > > > > > > > --
> > > > > > > > > > > Subscription 
> > > > > > > > > > > settings:http://groups.google.com/group/web2py/subscribe?hl=en

Reply via email to