Can't insert file into blob field

53 views
Skip to first unread message

Łukasz Szydłowski

unread,
Jun 4, 2024, 10:10:15 AM6/4/24
to py4web
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?


Łukasz Szydłowski

unread,
May 6, 2026, 3:19:17 AMMay 6
to py4web
It is an old issue, but still it was not resolved, so I created pull request for it.

Massimo DiPierro

unread,
May 9, 2026, 7:44:00 PMMay 9
to py4web
Merged. Thank you!
Reply all
Reply to author
Forward
0 new messages