mdipierro wrote:
You can do it both ways.
If you choose to retain the original names you will have to create
your own "download" action.
def mydownload(): return
response.stream(open(os.path.join(request.folder,'upload','/'.join(request.args)),'rb'))
You lose the ability to enforce granular access control.
I would follow Lukasz' advice and do from a web2py script
import glob
for filename in glob.glob('/path/to/files/*'):
db.yourtable.insert(yourfield=db.yourtable.yourfield.store(open(filename,'rb')))
(Third try - these posts just seem to keep disappearing into the ether.
Apologies if the posts sent a couple of days ago suddenly turn up too.)
Excellent suggestions, thank you Lukasz and Massimo.
I am constantly amazed at how easy web2py makes a lot of things.
But ... when I called store() as in Massimo's example, it returned:
Traceback (most recent call last):
File "/home/rowdy/web2py/gluon/restricted.py", line 173, in restricted
exec ccode in environment
File "/home/rowdy/web2py/applications/webacc2/controllers/system.py",
line 116, in <module>
File "/home/rowdy/web2py/gluon/globals.py", line 96, in <lambda>
self._caller = lambda f: f()
File "/home/rowdy/web2py/gluon/tools.py", line 1877, in f
return action(*a, **b)
File "/home/rowdy/web2py/applications/webacc2/controllers/system.py",
line 111, in attachments
db.attachment.insert(incident = incident_id, description =
'Migrated file', file = db.attachment.file.store(open(name, 'rb')),
original_filename = originalName)
File "/home/rowdy/web2py/gluon/sql.py", line 2613, in store
filename = file.filename
AttributeError: 'file' object has no attribute 'filename'
The first couple of lines in gluon/sql.py of store() are:
def store(self, file, filename=None, path=None):
if not filename:
filename = file.filename
The file object does not seem to have a filename property. It does have
a name property. Changing the second line as:
def store(self, file, filename=None, path=None):
if not filename:
filename = file.name
seems to work.
Rowdy
--
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.