Skip to content

Fix upload the file into blob field by using class Form#1043

Open
ls1luke wants to merge 4 commits intoweb2py:masterfrom
ls1luke:fix-blob-insert
Open

Fix upload the file into blob field by using class Form#1043
ls1luke wants to merge 4 commits intoweb2py:masterfrom
ls1luke:fix-blob-insert

Conversation

@ls1luke
Copy link
Copy Markdown

@ls1luke ls1luke commented Apr 29, 2026

Fix to be able to actually upload a file into blob field by using class Form.

Given table definition as below

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.

The fix is just a copy of solution used in web2py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant