response.download checks the db to get the uploadfolder from the upload 
field (which you don't have). Instead, you might be able to use 
response.stream directly:

import os
filename = [code to get filename from db]
response.stream(os.path.join(request.folder, 'uploads', filename), 
request=request)

You could also upload the files into the /static folder -- files in static 
can be accessed directly via URL without requiring a special download 
action:

URL('static', 'upload_subfolder', args=filename)

Anthony

On Monday, October 24, 2011 2:19:42 PM UTC-4, pepper_bg wrote:
>
> Have to go to the experts for this. I have a table for storing 
> arbitrary user data: 
>
> db.define_table('extra_attributes', 
> Field('user',       db.auth_user), 
> Field('name'), 
> Field('type', requires = IS_IN_SET(('text','file'))), 
> Field('value',  'string') ) 
>
> 'value' could be text of file. Then the controller looks like: 
>
> def upload_birth_certificate(): 
>     form = SQLFORM.factory( Field('document', 'upload', uploadfolder = 
> 'uploads') ) 
>     if form.accepts(request.vars, session): 
>         db.extra_attributes.insert( user=auth.user.id, name='birth 
> cert', type='file', value=form.vars['document'] ) 
>
> Like you notice I am bending the rules a little to make the 'value' 
> string field hold an upload path. This all works fine, uploads my 
> files and all, but turns out even if I know the file name and 
> location, using say 
> http://mysite.com/my_app/my_cont/download/uploads/no_table.document.9b6...b10.62...67.png
>  
> I can't get my files. 'download' is just the standard: 
>
> def download(): 
>     return response.download(request,db) 
>
> I can live with the uploads/no_table.document.9b6...b10.62...67.png 
> uploaded file name but Response.download insists on 'no_table' and 
> 'document' being actual table/column names. 
>
> I do have my reasons to keep my schema loose like this and not define 
> a dedicated 'upload' field and would explore other options before 
> messing with the schema. 
>
> So is there any way to change this behavior? What comes to mind is 
> somehow fool the Field or the Form to take an existing table/column 
> names so Response.download is happy but I am not sure it is absolutely 
> safe with no side effects downstream. Put another way can 'upload' 
> fields be used in truly generic SQLFORM.factory(...) forms? 
>
> Thanks for your help! 
>
>
>

Reply via email to