I have a multi-tenant application, where users can upload files. I save 
these in a different directory for each client (tenant), so I can keep tabs 
on the overall disk space and number of files uploaded by each.

This works when defined in a model:

FILE_PATH=os.path.join(request.folder, 'uploads', str(auth.user.client), 
'attachments')

db.define_table('attachment',
    Field('attached_file', 'upload', label="Upload new file", 
          uploadfolder=FILE_PATH, 
          requires=IS_NOT_EMPTY(), autodelete=True),
    Field('filename', type='string', length=150, writable=False),
    Field('request_tenant', type='integer', default=auth.user.client,
          readable=False, writable=False))

Uploaded files are stored in ../application/uploads/client#/attachments/.. 
and can be downloaded with URL('download', row['attached_file']). This is 
as I expected.

My problem is when I move the model definition to a module:

from gluon import *
import os
FILE_PATH=os.path.join(current.request.folder, 'uploads', str(current.auth.
user.client), 'attachments')

class Attachment(object):

    def __init__(self, db):
        self.db = db

    def define_tables(self):
        db = self.db
        if not 'attachment' in db.tables:
            db.define_table('attachment',
                Field('attached_file', 'upload', label="Upload new file", 
                      uploadfolder=FILE_PATH, 
                      requires=IS_NOT_EMPTY(), autodelete=True),
                Field('filename', type='string', length=150, writable=False
),
                Field('request_tenant', type='integer', default=current.auth
.user.client,
                      readable=False, writable=False))

Uploaded files continue to be stored in 
../application/uploads/client#/attachments/.. . However, URL('download', 
row['attached_file']) no longer works - it appears to look for the files in 
the standard ../application/uploads/ directory rather than the uploadfolder 
defined in the module.

So my question is, can anybody recommend how I access these files to 
download? Do I have to modify the standard download function ?

Thanks,

Andy

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to