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!


5;"";;"2013-07-29 18:27:00";505;"";"";"";"ZnJvbS...KQ=="
6;".py";1;"2013-07-29 18:27:14";;"form";
"fileobject.upload.97409537b5b00657.706f72747363616e2e7079.py";"portscan.py"
;""


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.

On Monday, July 29, 2013 5:55:09 PM UTC-7, Joe Barnhart wrote:
>
> I'm hitting a brick wall when trying to convert my table (under 
> PostgreSQL) to use "blob" storage.  The problem seems to be that web2py 
> doesn't properly recognize and initialize the blob field.  For example, 
> when I tried this:
>
>
>             db.define_table("fileobject",
>                 Field("upload_data","blob"),
>                 Field("upload","upload",uploadfield='upload_data'),
>                 ...
>
>
> The code fails when uploading the blob.  In the DAL, in the code for 
> Field.store():
>
>
>         self_uploadfield = self.uploadfield
>         if isinstance(self_uploadfield,Field):
>             blob_uploadfield_name = self_uploadfield.uploadfield
>             keys={self_uploadfield.name: newfilename,
>                   blob_uploadfield_name: file.read()}
>             self_uploadfield.table.insert(**keys)
>             ...
>  
>
> In this case, the test to see if self_uploadfield is a Field FAILS -- 
> because the uploadfield still has the string "upload_data", not the 
> corresponding Field.
>
> Next, I thought I'd try the old-school way, I put the Field definition as 
> the argument to uploadfield:
>
>
>             db.define_table("fileobject",
>                 
> Field("upload","upload",uploadfield=Field("upload_data","blob")),
>                 ...
>
>
> Again, this FAILS, but for a different reason -- the "table" attribute of 
> the "upload_data" Field never got initialized to "fileobject"!
>
> I just can't find a way around this.  I'm using web2py version 
> 2.5.1-stable under OSX (running from source).
>
> -- Joe B.
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to