Hi,
During porting web2py -> py4web app, I was unable to use Form() to upload file into blob field (using PostgreSQL).
Here is table def:
db.define_table('products',
Field('name', 'string', length=50),
Field('image', 'upload', uploadfield='image_data'),
Field('image_data', 'blob', default=''))
and respective action:
@action("new_product", method=["POST", "GET"])
@action.uses("new_product.html")
def new_product():
form = Form(db.products)
if form.accepted:
redirect(URL('index'))
return dict(form=form)
When submitting the form, image_data column in database was always null.
After some debugging, I found that generated sql query to database had 'image_data' null.
Here is fix in class Form (form.py), based on web2py code:
if field.type == "upload":
(...code...)
if isinstance(field.uploadfield, str):
validated_vars[field.uploadfield] = value.file.read()
elif field.type == 'blob':
pass
elif field.type == "boolean":
Would you check if it is ok?