in_row['f_file_xplatform'].retrieve(nameonly=True)
should be
db.t_products.f_file_xplatform.retrieve(
in_row['f_file_xplatform'],nameonly=True)
retrieve is a property of the field, not the value.
Anyway, you do not want to recompute the md5 every time the record is
updaded. Only when a new file is uploaded.
if request.vars.f_file_xplatform:
db.t_products.f_file_xplatform_download_name.compute=lambda r:
download_name(r,XPLATFORM)
else:
db.t_products.f_file_xplatform_download_name.writable = False
On Thursday, 28 March 2013 06:32:19 UTC-5, smoggy wrote:
Hello folks,
So i want to generate a md5 hash of uploaded files. How can this be done ?
here is my attempt
with the following code i get
AttributeError: 'str' object has no attribute 'retrieve'
So obviously the row elements are not Field type, and since i'm a python
newbie i couldn't figure this. Can anybody tip me on this ?
def md5_for_file(f):
...
return md5.digest()
db.define_table('t_products',
Field('id','id'),
Field('f_file_xplatform', type='upload'),
Field('f_file_xplatform_hash', type='string',label=T('Source File Hash')),
Field('f_file_xplatform_download_name', 'string', compute=lambda r:
download_name(r,XPLATFORM)),
)
def download_name(in_row,in_os):
try:
tt_row = in_row['f_file_xplatform'].retrieve(nameonly=True)
print tt_row: + tt_row
t_md5 = md5_for_file(tt_row[1])
in_row['f_file_xplatform_hash']=t_md5
return 'blabla.'+t_md5
except Exception, e:
import traceback
print traceback.format_exc()
--
---
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.