I thought I was on the correct path with this can soemone tell me where 
this is going wrong?

db.define_table('consumer',
                Field 
<http://127.0.0.1:8000/examples/global/vars/Field>('lname','string', 
requires=IS_NOT_EMPTY 
<http://127.0.0.1:8000/examples/global/vars/IS_NOT_EMPTY>()),
                Field 
<http://127.0.0.1:8000/examples/global/vars/Field>('fname','string', 
requires=IS_NOT_EMPTY 
<http://127.0.0.1:8000/examples/global/vars/IS_NOT_EMPTY>()),
                Field 
<http://127.0.0.1:8000/examples/global/vars/Field>('address','string'),
                Field 
<http://127.0.0.1:8000/examples/global/vars/Field>('city','string'),
                Field 
<http://127.0.0.1:8000/examples/global/vars/Field>('stayte','string'),
                Field 
<http://127.0.0.1:8000/examples/global/vars/Field>('zip','string'),
                Field 
<http://127.0.0.1:8000/examples/global/vars/Field>('h_phone','string'),
                Field 
<http://127.0.0.1:8000/examples/global/vars/Field>('c_phone','string'),
                Field 
<http://127.0.0.1:8000/examples/global/vars/Field>('adm_date','date'),
                Field 
<http://127.0.0.1:8000/examples/global/vars/Field>('dob','date'),
                Field 
<http://127.0.0.1:8000/examples/global/vars/Field>('pod','string'),
                auth.signature, #creates fields: created_on, created_by, 
modified_on, modified by, is_active
                format= lambda r: r.fname + ' ' + r.lname  #substitutes 
consumer.id for consumer name
                )
db.define_table('files',
                Field 
<http://127.0.0.1:8000/examples/global/vars/Field>('name', unique=True, 
length=255),
                Field 
<http://127.0.0.1:8000/examples/global/vars/Field>('phile', 'upload', 
custom_store=lambda file, filename, path: store_file(file, filename, path), 
custom_retrieve=lambda filename, path: retrieve_file(filename, path) ),
                Field 
<http://127.0.0.1:8000/examples/global/vars/Field>('consumerid', 'reference 
consumer'),
                auth.signature)

def store_file(file, filename=None, path=None):
    path = "applications/facesheet/uploads"
    if not os.path.exists(path):
         os.makedirs(path)
    pathfilename = os.path.join(path, filename)
    dest_file = open(pathfilename, 'wb')
    try:
            shutil.copyfileobj(file, dest_file)
    finally:
            dest_file.close()
    return filename
def retrieve_file(filename, path=None):
    path = "applications/facesheet/uploads"
    return (filename, open(os.path.join(path, filename), 'rb'))

def upload():
    var = request <http://127.0.0.1:8000/examples/global/vars/request>.args(0)
    var1 = request <http://127.0.0.1:8000/examples/global/vars/request>.args(1)
    var2 = request <http://127.0.0.1:8000/examples/global/vars/request>.args(2)
    form=SQLFORM <http://127.0.0.1:8000/examples/global/vars/SQLFORM>(db.files, 
upload=URL <http://127.0.0.1:8000/examples/global/vars/URL>("download"))
    form.vars.consumerid = var
    if form.process().accepted:
        response <http://127.0.0.1:8000/examples/global/vars/response>.flash = 
"files updated"
    query=(db.files.consumerid==var)
    form2=SQLFORM 
<http://127.0.0.1:8000/examples/global/vars/SQLFORM>.grid(query, args=[var, 
var1, var2], paginate=1, details=False, searchable=False, editable=False, 
csv=False, create=False, deletable=False, user_signature=False)
    return locals()

def download():
    if not request <http://127.0.0.1:8000/examples/global/vars/request>.args:
        raise HTTP <http://127.0.0.1:8000/examples/global/vars/HTTP>(404)
    name = request <http://127.0.0.1:8000/examples/global/vars/request>.args[-1]
    field = db["files"]["phile"]
    try:
        (filename, file) = field.retrieve(name)
    except IOError:
        raise HTTP <http://127.0.0.1:8000/examples/global/vars/HTTP>(404)
    #response.headers["Content-Type"] = c.contenttype(name)
    response 
<http://127.0.0.1:8000/examples/global/vars/response>.headers["Content-Disposition"]
 = "attachment; filename=%s" % name
    stream = response 
<http://127.0.0.1:8000/examples/global/vars/response>.stream(file, 
chunk_size=64*1024, request 
<http://127.0.0.1:8000/examples/global/vars/request>=request 
<http://127.0.0.1:8000/examples/global/vars/request>)
    raise HTTP <http://127.0.0.1:8000/examples/global/vars/HTTP>(200, stream, 
**response <http://127.0.0.1:8000/examples/global/vars/response>.headers)

*The upload functionality is working fine stores the relative information in 
the database*

*and saves the file on the server which i wanted the problem is when someone 
clicks on the file *

*from the form2 within the upload method. The link is 
**http://127.0.0.1:8000/facesheet/default/upload/1/John/Smith/download/test3.docx.*

*This brings back a 404 tried so many different examples on the web the few 
that are out there atleast*

*but I keep running into a brick wall. Thank You in advance.*

-- 
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/groups/opt_out.

Reply via email to