Having a little trouble with getting an attachment to work. This is a simplified version of the controller:
form = FORM('Attach', [INPUT(_name='attachment', _type='file')]) if form.accepts(request): v = form.vars.attachment if not v is None and not v == '': v = db.attachments.attachment.store(v) db(db.attachments.id==id).update(attachment = v) And this is the result: Traceback (most recent call last): File "/media/psf/Python/web2py/gluon/restricted.py", line 194, in restricted exec ccode in environment File "/media/psf/Python/web2py/applications/marlin/controllers/default.py" <https://172.16.100.111:8000/admin/edit/marlin/controllers/default.py>, line 586, in <module> File "/media/psf/Python/web2py/gluon/globals.py", line 149, in <lambda> self._caller = lambda f: f() File "/media/psf/Python/web2py/applications/marlin/controllers/default.py" <https://172.16.100.111:8000/admin/edit/marlin/controllers/default.py>, line 471, in view_invite v = db.rfq_item[field].store(v) File "/media/psf/Python/web2py/gluon/dal.py", line 5557, in store shutil.copyfileobj(file, dest_file) File "/usr/lib/python2.6/shutil.py", line 27, in copyfileobj buf = fsrc.read(length) File "/usr/lib/python2.6/cgi.py", line 522, in __getattr__ raise AttributeError, name AttributeError: read The code for using store(v) came from another thread. When I print out v before calling store(), it prints out something like this: FieldStorage('attachment', 'filename.txt', 'The actual text of the file') Looking through the dal.py, it looks like the line "shutil.copyfileobj(file, dest_file)" is expecting an actual File object, not a FieldStorage object, hence the attribute error. But if I try to pass "storage(v.file)" instead of "storage(v)", then the DAL errors out because it's expecting a FieldStorage object, not a File object. Is this a bug or am I doing something wrong here? I should mention that using SQLFORM and SQLFORM.factory with attachments works just fine, it's only FORM that is giving me trouble.