In your controller/default.py you probably have function defined as:
def download(): return response.download(request,db)
To view a picture do something like this in your controller:
record = db(db.t_student.id == 2).select()
if len(record):
record = record[0]
return dict(record=record)
In View:
{{=TAG.img(_width=90, _src=URL(r=request, c='default', f='download',
args=[record.f_image]))}}
What I do when users are uploading pictures is to create a thumbnail of
that picture and usually only show that thumbnail.
Kenneth
I have used the wizard to start working on an app. one of the tabled
upload an file (image). How should I modify the view/control to
display the image? The view and control and db are those created by
the wizard but I have pasted them below.
What is the recommended way to require the uploaded file be a jpg?
I assume what I am asking is documented somewhere I just could not
find it. What should I be reading to know more about images and
web2py?
db.define_table('t_student',
Field('id','id',
represent=lambda id:SPAN(id,'
',A('view',_href=URL('student_read',args=id)))),
Field('f_first_name', type='string', notnull=True,
label=T('First Name')),
<SNIP>
Field('f_image', type='upload',
represent=lambda x: x and
A('download',_href=URL('download',args=x)) or '',
label=T('Image')),
<SNIP>
CONTROLLER
@auth.requires_login()
def student_read():
record = db.t_student(request.args(0)) or redirect(URL('error'))
form=crud.read(db.t_student,record)
return dict(form=form)
VIEW
{{extend 'layout.html'}}
<h2>Read student</h2>
{{=A(T('edit
student'),_href=URL('student_update',args=request.args(0)))}}
<br/>
{{=form}}
{{for t,f in db.t_student._referenced_by:}}{{if not
t[-8:]=='_archive':}}
[{{=A(t[2:],_href=URL('%s_select'%t[2:],args=(f,form.record.id)))}}]
{{pass}}{{pass}}
Thanks
Vincent