Database administration - db upload field

22 views
Skip to first unread message

ab

unread,
Sep 10, 2009, 11:57:31 AM9/10/09
to web2py-users
Hi

I found issue in database administration module and blob field for
files storage

When model is defined as below

db.define_table('picture', Field('file','upload'))

there is no problem with inserting new records using 'database
administration'

but when model is defined to store files in database as below

db.define_table('picture',
Field('file','upload',uploadfield='file_data'),
Field('file_data','blob'))

'database administration' can't insert new record.

I don't know if this is issue or current limitation.

Regards

mdipierro

unread,
Sep 10, 2009, 1:25:47 PM9/10/09
to web2py-users
Please try

Field('file_data','blob',default=''))

ab

unread,
Sep 10, 2009, 3:19:49 PM9/10/09
to web2py-users
Thanks. Working fine.

I have one more question.

When I upload file by database administration, field file contains for
example following entry -
picture.file.975598ae58526cda.
46697265666f785f77616c6c70617065722a706a67.png

I want to upload files by REST. Is there function which I can use to
calucate file field value as above?

mdipierro

unread,
Sep 10, 2009, 3:27:04 PM9/10/09
to web2py-users
It depends on how you send the file. Can you send me an example?

ab

unread,
Sep 10, 2009, 3:40:56 PM9/10/09
to web2py-users
I don't know uploaded file name. There is only stream of bytes to save
in blob field.

mdipierro

unread,
Sep 10, 2009, 4:36:13 PM9/10/09
to web2py-users
def upload():
import cStringIO
data=request.body.read()
f=cStringIO.StringIO(data)
current_filename='bla.bla' # how to you know the file extension if
you do not pass the name?
new_filename=db.mytable.picture.store(f,current_filename)
# do something with new_filename and data

yamandu

unread,
Oct 6, 2009, 12:05:16 AM10/6/09
to web2py-users
I was almost blaming SQLite and almost changed it.
Why the need of the default attribute?
Is this a bug? I did not understand.

mdipierro

unread,
Oct 6, 2009, 12:12:04 AM10/6/09
to web2py-users
I do not understand the question

Massimo
Reply all
Reply to author
Forward
0 new messages