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.
>
>
--