#controller
text_form=SQLFORM.factory(Field('text_in','text',db.doc))
file_form=SQLFORM.factory(db.doc)
...
if text_form.accepts(request.vars,formname='text_form'):
#insert data into the doc table
...
if file_form.accepts(request.vars,formname='file_form'):
# etc
The view has custom forms for both text_form and file_form.
The question is ... how to properly insert data into the doc table in
the case of the text_form? text_form.vars.text_in has the results of
textarea form field. These data are easily stored in an uploads/
file.txt file. The question is how to make the db.doc.filename field
point to the uploads/file.txt file such that it will be consistent
with a true file upload vs. a text field upload? Just inserting the
name of the uploads/file.txt into the db.doc.filename field isn't the
right way. (Hope this is clear enough.)
db.doc.insert(filename=db.doc.filename.store
(request.vars.xyz.file,request.vars.xyz.filename))
> > right way. (Hope this is clear enough.)- Hide quoted text -
>
> - Show quoted text -
You should not mess up with uploads. Let SQLFORM put staff there and
download retrieve it. You can manually do it but ONLY if you use
db.table.insert(fieldname=db.table.fieldname.store
(stream,'filename'))
This is very special folder because there are a lot of security
implications in having users uploads data (directory traversal
attacks) and download data (authorizations). Let web2py deal with it
by the book. It is complicated. There is a lot of code in web2py just
to deal with this.
Files that public should go in static/.
Everything else should go in private but now you are on your own. You
decide file naming conventions but you are also responsible for
security holes.
Massimo
Most filesystems will suffer a huge performance penaltiy if there are
> 100 files in a single folder.
So in an app that receives alot of uploads, having these all in one
folder is really really bad for the servers performance (think flickr
type site).
How could web2py handle a subfolder structure, that put the files that
were uploaded by date/time etc, something that keeps more than 100
files in any given folder ?
-Thadeus
> --
> You received this message because you are subscribed to the Google Groups "web2py-users" group.
> To post to this group, send email to web...@googlegroups.com.
> To unsubscribe from this group, send email to web2py+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
>
>
>
>
Field('file','upload',uploadfolder='....')
any field can have its own uploadfolder which can me (but does not
need to be) a subfolder of uplaods/
On Jan 7, 4:59 pm, Thadeus Burgess <thade...@thadeusb.com> wrote:
> There is an issue with the uploads folder.
>
> Most filesystems will suffer a huge performance penaltiy if there are
>
> > 100 files in a single folder.
>
> So in an app that receives alot of uploads, having these all in one
> folder is really really bad for the servers performance (think flickr
> type site).
>
> How could web2py handle a subfolder structure, that put the files that
> were uploaded by date/time etc, something that keeps more than 100
> files in any given folder ?
>
> -Thadeus
>
> > > For more options, visit this group athttp://groups.google.com/group/web2py?hl=en.- Hide quoted text -
> > > > For more options, visit this group athttp://groups.google.com/group/web2py?hl=en.-Hide quoted text -
I'm doing this to store an uploaded file:
db.doc.insert(filename=db.doc.filename.store
(request.vars.filename.file,request.vars.filename.filename))
where doc is a table with ... Field('filename','upload') ...
Problem is, I get a file with name no_table.filename.crypto-string.txt
and doc.filename.crypto-string.txt, where the doc.filename.crypt-
string.txt is empty and the no_table.filename.crypto-string.txt has my
uploaded text file. So this obviously isn't working. What do you think
I'm doing wrong?