I had an idea to work around the problem...
Define the blob field in the table and then set the "uploadfield" parameter (of the "upload" field) AFTER table creation! Perfect (I thought), I'll have the contents of the uploadfield as a Field (not a string) and I'll have the "table" attribute of the blob field set to the proper table.
db.define_table("fileobject",
Field("upload_data","blob"),
Field("upload","upload",uploadfield="upload_data"),
...)
db.fileobject.upload.uploadfield=db.fileobject.upload_data
It shoulda worked... But it didn't.
The problem was that the line:
blob_uploadfield_name = self_uploadfield.uploadfield
Now resolves to "True" -- because the blob field has its upload field parameter set to "true" by default.
Fine, I'll change the DAL and set it to the name of the blob field.
blob_uploadfield_name = self_uploadfield.name
Hooray! I finally loaded data into my blob field! Only... it loaded TWO ROWS in the table. The first row holds only the binary data (and a length field I computed) while the next row holds all the metadata!
Looking at the code, I can see the handling for "upload" to a blob field results in an immediate "insert" statement, and that generates a row in the table without waiting for any other fields.
self_uploadfield.table.insert(**keys)
I would stake my meager reputation as a Python code reader that the "upload" to blob feature of web2py has been majorly borked, perhaps in a recent update. It doesn't work anything like described in the PDF or online book. It appears almost like it expects a separate upload TABLE, and it inserts the data into that other table while processing the insert for the "master" table.
If anyone is using 2.5.1 to store data in a database as blobs, and is not using GAE, how'd you do it??!?
-- Joe B.