Where do upload files get stored?

69 views
Skip to first unread message

pumplerod

unread,
Mar 21, 2015, 1:30:44 AM3/21/15
to web...@googlegroups.com

I've just gotten uploading an image file with SQLFORM.factory to work (thanks to the posts here in this forum), but I have to admit I'm totally confused.

I specified the uploads directory in which to store the image

SQLFORM.factory(db.auth_user,db.brands,  Field('brand_logo', 'upload', uploadfolder=os.path.join(request.folder, 'uploads/')))



The upload works, when I check the database, and select the file link, the image file downloads.  However, I can't find it anywhere in the framework.  There's nothing in the uploads directory.  So is the image being stored in the SQLite database?


Massimo Di Pierro

unread,
Mar 21, 2015, 4:07:10 PM3/21/15
to web...@googlegroups.com
I am confused too. Given your form, it should go on the filesystem. You use a SQLFORM.factory, not a SQLFORM therefore there is no DB IO. Since you can download it it means you have the filename, you can try search for it. Perhaps the 'upload/' instead of 'upload' is creating a problem?

pumplerod

unread,
Mar 21, 2015, 4:53:29 PM3/21/15
to web...@googlegroups.com
Well, I found the images.  they are in the parent directory of applications.  meaning the root web2py directory.  I'm not sure why.  is seems as though the os.path.join() is not actually building the correct path.  Perhaps request.folder() is not being called correctly?

pumplerod

unread,
Mar 21, 2015, 5:04:59 PM3/21/15
to web...@googlegroups.com
It seems part of my error was in using the "/" before the "uploads/"

This generates the correct path...

os.path.join(request.folder,'uploads/')



this does not...

os.path.join(request.folder,'/uploads/')


that said however.  They each place the uploaded file into a root level uploads directory.

pumplerod

unread,
Mar 21, 2015, 5:18:11 PM3/21/15
to web...@googlegroups.com
I found the problem.  In my models file I had declared the model to have uploadfolder='uploads/'  Evidently this does not get overridden when I declare the field in the SQLFORM.factory

Niphlod

unread,
Mar 21, 2015, 5:27:30 PM3/21/15
to web...@googlegroups.com
Beware......something is wrong with your usage of os.path.join.
All the arguments passed should not have ANY "path separator" inside, that's the whole deal of os.path.join.
Else, you may just concatenate strings by hand!!!

>>> import os
>>> os.path.join('a', 'b', 'c')
'a/b/c'
>>> os.path.join('a', 'b', 'c/')
'a/b/c/'
>>> os.path.join('a', 'b', '/c/')
'/c/'
>>>

Reply all
Reply to author
Forward
0 new messages