uploadfolder=request.folder not working as it expected

67 views
Skip to first unread message

mostwanted

unread,
Oct 5, 2020, 12:21:43 PM10/5/20
to web2py-users
uploadfolder=request.folder+'static/docs'  suddenly aint working as it should, initially is worked. What should happen is that when i save a PDF file it should be save in a static folder called docs  & in a database table but the docs folder in static doesnt get created now I am getting the 404 NOT FOUND when i try to view or open the PDF. I dont know why this is suddenly happening when it used to work, do i need import some python library or change my code somwhere?

CODE:
model:
db.define_table('pdfs',
                Field('Form_Name', label=SPAN('Document Title', _style="font-weight: bold;"), widget=lambda field, value:SQLFORM.widgets.string.widget(field, value, _placeholder="Invoice/PO/Quotation Name")),
                Field('status', 'boolean', label=SPAN('Status (For Invoices Only)', _style="font-weight: bold;")),
                Field('status_condition', requires=IS_IN_SET(['Quotation', 'Paid', 'Unpaid', 'Cancelled', 'Paid With Balance'], zero=None), label=SPAN('Status Condition', _style="font-weight: bold;")),
                Field('fileS','upload',uploadfolder=request.folder+'static/docs', label=SPAN('Upload Files', _style="font-weight: bold;")))

CONTROLLER:
def saveDocument():
    form=SQLFORM(db.pdfs)
    if form.process().accepted:
        response.flash=T('Form Saved')
    return locals()

def viewer():
    row = db(db.pdfs.id==request.args(0)).select(db.pdfs.fileS).first()
    redirect(URL('static','docs',args=row.fileS))

VIEW FOR SAVED DOCUMENT VIEWING
{{extend 'layout.html'}}
{{for details in details2: }}
<div id="formIcon">{{=A(details.Form_Name, _target="_blank", _href=URL('viewer', args=details.id))}} <br />
{{pass}}
</div>

Regards;

Mostwanted

villas

unread,
Oct 6, 2020, 7:43:37 AM10/6/20
to web2py-users
Maybe you are not using a separator (eg '/').  Try something like this:

uploadfolder = os.path.join(request.folder, 'static/docs')

mostwanted

unread,
Oct 8, 2020, 2:41:55 PM10/8/20
to web2py-users
This worked, thanks Villas
Reply all
Reply to author
Forward
0 new messages