When playing around with uploads, I tried to get the example from the
web2py book working:
def form_from_factory():
form = SQLFORM.factory(
Field('your_name', requires=IS_NOT_EMPTY()),
Field('your_image', 'upload'))
if form.accepts(request.vars, session):
response.flash = 'form accepted'
session.your_name = form.vars.your_name
session.filename = form.vars.your_image
elif form.errors:
response.flash = 'form has errors'
return dict(form=form)
When run, it gave me this error (on a brand new version 1.95.1)
Traceback (most recent call last):
File "/home/jon/code/sandpit/web2py/gluon/restricted.py", line 181,
in restricted
exec ccode in environment
File "/home/jon/code/sandpit/web2py/applications/upload/controllers/
upload.py", line 14, in <module>
File "/home/jon/code/sandpit/web2py/gluon/globals.py", line 133, in
<lambda>
self._caller = lambda f: f()
File "/home/jon/code/sandpit/web2py/applications/upload/controllers/
upload.py", line 6, in form_from_factory
if form.accepts(request.vars, session):
File "/home/jon/code/sandpit/web2py/gluon/sqlhtml.py", line 1146, in
accepts
newfilename = field.store(source_file, original_filename)
File "/home/jon/code/sandpit/web2py/gluon/dal.py", line 4966, in
store
raise RuntimeError, "you must specify a
Field(...,uploadfolder=...)"
RuntimeError: you must specify a Field(...,uploadfolder=...)
To fix it I had to
- import os
- change the upload field to
Field('your_image', 'upload',
uploadfolder=os.path.join(request.folder,'uploads'))
I thought uploadfield should default to what I have added, from the
description of Field in the book.
Have I done something stupid?