Please do.

On Sunday, 18 November 2012 23:21:16 UTC-6, Cliff Kachinske wrote:
>
> Aha.
>
> I could not find the call to stream.read in the pdf manual.
>
> Manual uploads appears to be removed from the on-line manual.  Is that 
> intentional?  If not I could write up a patch for the book in the next day 
> or so.
>
> By the way, the code allows uploads to be attached to any table in the 
> application.  I can put it on github with a bsd license if you think anyone 
> would be interested.
>
> Cliff Kachinske
>
> On Friday, November 16, 2012 5:20:07 PM UTC-5, Massimo Di Pierro wrote:
>>
>> Yes:
>>
>>     att_id = db2.attachments.insert(
>>                     attachment = db2.attachments.attachment.store(...),
>>                     filename = fname,
>>                     Description = 
>> r.attachments.attachment_brief_description,
>>                     )
>> needs
>>
>>     att_id = db2.attachments.insert(
>>                     attachment = db2.attachments.attachment.store(...),
>>                     payload = stream.read(),
>>                     filename = fname,
>>                     Description = 
>> r.attachments.attachment_brief_description,
>>                     )
>>
>> On Friday, 16 November 2012 09:18:47 UTC-6, Cliff Kachinske wrote:
>>>
>>> The title describes the problem.
>>>
>>> Any suggestions as to what I might do?  Would it be simpler if I just 
>>> uploaded to a directory?  I'm archiving for auditability, so I suppose 
>>> there would still be a way to get at earlier versions of uploaded files.
>>>
>>> Here is the model:
>>>
>>> db.define_table('attachments',
>>>         Field('attachment', 'upload', uploadfield='payload'),
>>>         Field('filename', length=512),
>>>         Field('Description', 'text'),
>>>         Field('payload', 'blob'),
>>>         migrate=init_migrate,
>>>         )
>>> Common fields are auth.signature and a field called "tenant_link", which 
>>> is how I implemented the request_tenant functionality before Massimo 
>>> announced it.
>>>
>>> Here is the controller code:
>>>    for r in rows:
>>>         ...
>>>         myfile = mypath + r.attachments.file_name + '.' + 
>>> r.attachments.file_ext
>>>         try:
>>>             stream = open(myfile, 'rb')
>>>         except IOError:
>>>             no_finds.append(DIV('unable to find {}'.format(myfile)))
>>>             continue
>>>         else:
>>>             ok.append(DIV('found {}.{}, aka {}'.format(
>>>                 r.attachments.file_name, r.attachments.file_ext, fname
>>>                 )))
>>>             att_id = db2.attachments.insert(
>>>                     attachment = db2.attachments.attachment.store(
>>>                         stream, '{}.{}'.format(
>>>                             r.attachments.file_name, 
>>> r.attachments.file_ext
>>>                             )
>>>                         ),
>>>                     filename = fname,
>>>                     Description = 
>>> r.attachments.attachment_brief_description,
>>>                     )
>>>
>>> The insert is successful except the payload field is never populated. 
>>>  Here is a snippet  of the results from this postgres query, "SELECT id, 
>>> filename, octet_length(payload) from attachments;"
>>>
>>>   9 | apt-get-output.txt                                                 
>>>                  |        10772
>>>   10 | a_h_hits.txt                                                     
>>>                    |        24164
>>>   11 | a_h_hits.txt                                                     
>>>                    |        24164
>>>   12 | greg-free-bizcard                                                 
>>>                   |       215288
>>>   27 | Tank Thickness ML.doc                                             
>>>                   |             
>>>   28 | Tank Thickness ML.doc(1)                                         
>>>                    |             
>>>   29 | A short short file                                               
>>>                    |             
>>>   30 | hello.txt                                                         
>>>                   |        
>>>
>>> Records 9, 10 and 11 were uploaded while testing the interface. Records 
>>> 12 and up were created using the above script.     
>>>
>>>

-- 



Reply via email to