On Friday, October 28, 2011 10:38:10 AM UTC-4, Ross Peoples wrote: > > 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')]) >
Is the above a typo? INPUT should either not be in a list, or the list should be preceded by a *. Also, don't you need a submit button? > > if form.accepts(request): > v = form.vars.attachment > if not v is None and not v == '': > v = db.attachments.attachment.store(v) > v = db.attachments.attachment.store(v.file, v.filename) works for me. > 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. > > Looks like Field.store() is expecting a file object, not a FieldStorage (the only place it does anything with 'file' is when calling shutil.copyfileobj).