As I mentioned, when you originally upload the file, web2py creates a new 
filename with the following form: 
mytable.myfield.[16-char-uuid].[base16-encoded 
'myfile'].pdf. Notice that the table and field are included at the 
beginning of the filename. This filename is what gets stored in the upload 
field. In order to download the file, you have to retrieve this filename 
from the db, and then add it as the last argument of the URL that calls the 
download function. The download function gets the table and field names 
from the filename itself.

Let's say you have:

db.define_table('mytable', Field('myfield', 'upload'))

Then you upload a file called 'myfile.pdf'. When you upload that file, 
web2py renames the file to something like 
'mytable.myfield.a0a2facdcdb41ced.6D7966696C65.pdf', stores the renamed 
file in the /uploads folder, and stores that new name in the 'myfield' 
field of 'mytable', like this:

*id*  *myfield*
1   mytable.myfield.a0a2facdcdb41ced.6D7966696C65.pdf

Later, let's say you want to construct a URL to download the file. You 
first have to retrieve the filename from the db by referencing that record.

file = db.mytable[1].myfield  # this retrieves the filename of record 1
url = URL('default', 'download', args=file) # this builds the download url 
with the filename

In this case, url will be 
'/yourapp/default/download/mytable.myfield.a0a2facdcdb41ced.6D7966696C65.pdf'. 
This assumes a download function in default.py:

def download():
    return response.download(request, db)

Hope that clears it up.

Anthony


On Thursday, November 3, 2011 8:00:58 AM UTC-4, lucas wrote:
>
> ok, still confused, exactly how do you pass the table and field to the 
> response.download.  i don't see it in the parameters.  how does it 
> extract the table and field from the data provided.  from the request 
> somehow?  lucas

Reply via email to