DAL upload Field manual uplad to DB

340 views
Skip to first unread message

kachna

unread,
Sep 2, 2010, 1:17:47 PM9/2/10
to web2py-users
Hi once again today!
I am trying manual upload on table with upload field(book:
http://web2py.com/book/default/chapter/06#Manual-Uploads). My model
store data in database:

db.define_table('photo',
Field('photo', 'upload', uploadfield='photo_data'),
Field('photo_data', 'blob')
)


this pass:

db.photo.insert(photo=db.photo.photo.store(open(..., 'rb'), 'file
name.ext'))

but in database is no data. Just UUID file name in "photo" field.

I checked source and store method is prepare to store file on
filesystem only, so file data can't be in DB. I can't find method
which upload data into DB when SQLFORM is used.

Any Idea? Thx

mdipierro

unread,
Sep 2, 2010, 4:10:03 PM9/2/10
to web2py-users
You have to do it manually:

stream=open(..., 'rb')
db.photo.insert(photo=db.photo.photo.store(stream,
'filename.ext'),photo_data=stram.read())

this is because when you use insert you have to specify the field
name.

Ate the form level this is automatic.
Reply all
Reply to author
Forward
0 new messages