image uploading and storing in web2py

1,620 views
Skip to first unread message

Saurabh S

unread,
Oct 17, 2011, 1:22:52 AM10/17/11
to web2py-users
Hi , i am developing an online booking system using web2py ...i have
come across a requiremnt where i need to store the clients photo into
the database(< 2MB)...how should i proceed with this...i mean what
should be the field in database....how i can populate a select image
box so that user/admin can upload a image into the DB.....


Please suggest....

Johann Spies

unread,
Oct 17, 2011, 2:49:00 AM10/17/11
to web...@googlegroups.com
Search the book for 'image'  and you will find a lot of references.

Here is an quote from early in the book (http://web2py.com/book/default/chapter/01?search=image):

"Here are some examples of web2py statements that illustrate its power and simplicity. The following code:
1.
db.define_table('person', Field('name'), Field('image', 'upload'))

creates a database table called "person" with two fields: "name", a string; and "image", something that needs to be uploaded (the actual image). If the table already exists but does not match this definition, it is altered appropriately."

Regards

Johann

--

Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

Bruno Rocha

unread,
Oct 17, 2011, 3:57:32 AM10/17/11
to web...@googlegroups.com
If your image needs to be stored in database (not in filesystem) do:

Field('name','upload',uploadfield="myblob"),Field('myblob','blob',default='')

Gour

unread,
Oct 17, 2011, 4:19:54 AM10/17/11
to web...@googlegroups.com
On Mon, 17 Oct 2011 05:57:32 -0200
Bruno Rocha <rocha...@gmail.com> wrote:

> If your image needs to be stored in database (not in filesystem) do:

Is it, in general, recommended to store image (blob) of such size in the
{sqlite3,postgresql} database?


Sincerely,
Gour


--
When your intelligence has passed out of the dense forest
of delusion, you shall become indifferent to all that has
been heard and all that is to be heard.

http://atmarama.net | Hlapicina (Croatia) | GPG: 52B5C810

signature.asc

Bruno Rocha

unread,
Oct 17, 2011, 6:13:38 AM10/17/11
to web...@googlegroups.com
The recommended is:

Store the pictures on the file system and picture locations in the database.

Why? Because...

  1. You will be able to serve the pictures as static files.
  2. No database access or application code will be required to fetch the pictures.
  3. The images could be served from a different server to improve performance.
  4. It will reduce database bottleneck.
  5. The database ultimately stores its data on the file system.
  6. Images can be easily cached when stored on the file system.

But if it is a requirement to store in database there is not to do about.
--



--
Bruno Rocha
[ Aprenda a programar: http://CursoDePython.com.br ]
[ O seu aliado nos cuidados com os animais: http://AnimalSystem.com.br ]
[ Consultoria em desenvolvimento web: http://www.blouweb.com ]

Gour

unread,
Oct 17, 2011, 6:34:11 AM10/17/11
to web...@googlegroups.com
On Mon, 17 Oct 2011 08:13:38 -0200
Bruno Rocha <rocha...@gmail.com> wrote:

> The recommended is:
>
> Store the pictures on the file system and picture locations in the
> database.

OK.

> But if it is a requirement to store in database there is not to do
> about.

I should be more clear saying that I was thinking about desktop (pyqt app)
probably using sqlite3.

For the web app, I agree with the points you've mentioned and will save 'em for
the future reference. ;)

Thank you.


Sincerely,
Gour


--
One who restrains his senses, keeping them under full control,
and fixes his consciousness upon Me, is known as a man of
steady intelligence.

signature.asc

Saurabh S

unread,
Oct 17, 2011, 7:59:56 AM10/17/11
to web...@googlegroups.com
hi thanks for you reply...please tell me how can i store the path of image into the databse and actuall image image on the file system ?...i mean what would the field in database.....if i go with this approach will i be able to view the same image when i edit a perticuler client...please reply

Saurabh S

unread,
Oct 17, 2011, 8:02:42 AM10/17/11
to web...@googlegroups.com
Hi ,  i am developing an online booking system using web2py ...i have 
come across a requiremnt where i need to store the clients photo into 
the database(< 2MB)...how should i proceed with this........ .... .i 
have achieved the functionality to store a image into the database 
when i create a perticuler client...but the problem is the " same 
image should be visible" when the we edit the clients page..but this 
is not happening....when i checked in appadmin that image is getting 
stored into the DB ....but i am unable to retrieve it back(for 
viewing) on the edit client page 
for storing i have used a DB field i.e. , Field('image','upload') 

also i am using 
 <td>{{=form.custom.label.image}}:</td> 
 <td>{{=form.custom.widget.image}}</td> 

how i can retrieve image back so that it becomes visible in smaller 
size on the edit client page 
Please suggest ... 



On Mon, Oct 17, 2011 at 3:43 PM, Bruno Rocha <rocha...@gmail.com> wrote:

pbreit

unread,
Oct 17, 2011, 8:31:23 PM10/17/11
to web...@googlegroups.com
Have you reviewed the example in the Book?
Reply all
Reply to author
Forward
0 new messages