In the first case there is no problem. In the second case it is
complicated because the data has to be encoded somehow. web2py assumes
enctype="multipart/form-data". This is transparent to web2py but there
are many parts that may fail, from form parsing to database back-end.
I would not recommend doing it unless mime/json encode the binary data
before sending it.
Massimo
Massimo
> from fileutils import copystream
> request.body.seek(0)
random_name=str(time.time())+str(randint(10000,99999))
filename=os.path.join(request.folder,'uploads',random_name)
copystream(request.body, open(filename,'wb'), int
(request.env.content_length))
db.yourtable.insert(file=filename,.....other fields....)
>
But there is a better way... in a subsequent email...
class Field:
def __init__(self,file): self.file=file
db.define_table('mytable',SQLField('file','upload'))
request.vars.file=Field(request.body)
form=SQFORM(db.mytable)
form.accepts(request.vars,formname=None) ### will do everything for you