download with original uploaded file name

7 views
Skip to first unread message

Wes James

unread,
Feb 13, 2009, 10:51:35 PM2/13/09
to web2py Web Framework
Massimo,

This works as long as there is a field called 'filename' in db.py.

stick this in t2.download at the bottom:

return rows[0][uploadfield]
else:
try:
row=db(db[t][f]==name).select(db[t]['filename'])
response.headers['Content-Disposition']='attachment;
filename="%s"' % row[0].filename
except:
pass

filename=os.path.join(request.folder,'uploads',name or
self._error())
return response.stream(filename)

Reply all
Reply to author
Forward
0 new messages