Unable to save pdf documents in my app

21 views
Skip to first unread message

mostwanted

unread,
Mar 29, 2022, 2:00:20 AMMar 29
to web2py-users
Guys my app suddenly wont save PDF documents.

db.define_table('pdfs',
                Field('fileS','upload',uploadfolder=request.folder+'static/pdfs')).

 The above code does not create static/pdfs folder as expected so when i click on the link thats supposed allow me to view the pdf  {{=A('Click to view', _href=URL('default', 'viewer'))}} it get an error 404 NOT FOUND !!!!

Am i missing something or is there a workaround this issue?

regards

mostwanted

unread,
Mar 29, 2022, 2:07:26 AMMar 29
to web2py-users
I tried to change this line:
Field('fileS','upload',uploadfolder=request.folder+'static/pdfs'))
to this below
Field('fileS','upload',uploadfolder=os.path.join(request.folder, 'static/profile'))

but still nothing works....!!!

Jim S

unread,
Mar 29, 2022, 8:00:18 AMMar 29
to web2py-users
I would first suspect a security issue.

Have you confirmed that the folder exists?  If so, does the file exist?

-Jim

mostwanted

unread,
Mar 29, 2022, 3:37:23 PMMar 29
to web2py-users
The file exists but only in the database but the folder in static doesnt exist, i thought the folder gets created with the first database entry

Jim S

unread,
Mar 29, 2022, 3:41:43 PMMar 29
to web2py-users
I think the folder would be created.  However, the security must be setup properly for it to happen.

Is this on a production box?  Linux?

-Jim

mostwanted

unread,
Mar 29, 2022, 10:51:42 PMMar 29
to web2py-users
Yes it is

Jim S

unread,
Mar 29, 2022, 10:57:01 PMMar 29
to web2py-users
Does the user that is running the web2py server have rights to create the directory and files inside that directory?

-Jim

mostwanted

unread,
Mar 29, 2022, 11:10:31 PMMar 29
to web2py-users
Yes they do

Clemens

unread,
Mar 30, 2022, 3:25:13 AMMar 30
to web2py-users
A few years ago I had to create a directory by web2py. I did it as follows:
from subprocess import Popen
...
create_dir = Popen(['mkdir', '%s%s' %(destination, build_date.strftime('%Y-%m-%d-%H%M%S'))], stderr=PIPE)

Thus, if the directory is not available you can create it. I guess the return value of Popen will tell you.

Maybe it helps.

Regards
Clemens

On Tuesday, March 29, 2022 at 8:00:20 AM UTC+2 mostwanted wrote:

mostwanted

unread,
Mar 30, 2022, 11:17:36 AMMar 30
to web2py-users
Thank you Clemens
Reply all
Reply to author
Forward
0 new messages