There are two issues here.
One is that the manual needs to be updated. Nobody should be doing
this
> def download():
> import os
> path=os.path.join(request.folder,'uploads',request.args[0])
> return response.stream(path)
Instead you should be doing this:
def download(): return response.download(request,db)
else you miss a lot of new web2py features, like the ability to
retrieve the file when it is stored in the database and set the
content-disposition to the original filename.
- the second issue (your specific problem) has no solution. A pdf file
is not an image and if you link it in a <img /> tag your browser will
not display it. web2py treats the file transparently and serves the
file. It is the browser that does not know how to handle the pdf.
Massimo
On May 22, 10:36 pm, ed <[email protected]> wrote:
> Hi,
> I tried the Web2py manual sample in article "3.6 An Image Blog" and it
> worked well with jpeg files, failed to display pdf files. The file
> extension in "uploads" folder revealed jpeg files doesn't have
> extension but pdf files has. I tried Massimo's solution on
> "pdf/doc attachments work in sqlite, not in gql" but didn't work
> either, maybe not applicable or missed something. Massimo's solution:
> 1) the download action should be
> def download(): return response.download(request,db)
>
> This will be modified later for download of application forms.
> Solution will be along this lines. The following is the code(I copied
> it in Web2py manual article 3.6):
>
> models/db.py
> --------------------
> db.define_table('image',
> SQLField('title'),
> SQLField('author'),
> SQLField('file','upload'))
>
> db.define_table('comment',
> SQLField('image_id', db.image),
> SQLField('author'),
> SQLField('email'),
> SQLField('body','text'))
>
> controllers/default.py
> ------------------------------
> def index():
> images=db().select(db.image.ALL,orderby=db.image.title)
> return dict(images=images)
>
> def show():
> image=db(db.image.id==request.args[0]).select()[0]
> form=SQLFORM(db.comment,fields=['author','email','body'])
> form.vars.image_id=image.id
> if form.accepts(request.vars,session):
> response.flash='your comment is posted'
> comments=db(db.comment.image_id==image.id).select()
> return dict(image=image,comments=comments,form=form)
>
> def download():
> import os
> path=os.path.join(request.folder,'uploads',request.args[0])
> return response.stream(path)
>
> views/default/index.html
> ----------------------------------
> {{extend 'layout.html'}}
> <h1>Current Images</h1>
> <u1>
> {{for image in images:}}
> {{=LI(A(image.title,_href=URL(r=request,f="show",args=[image.id])))}}
> {{pass}}
> </ul>
>
> views/default/show.html
> ----------------------------------
> {{extend 'layout.html'}}
> <h1>Image: {{=image.title}}</h1>
> <center>
> <img width='300px' height='600px' src="{{=URL
> (r=request,f='download',args=[image.file])}}"/>
>
> </center>
> {{if len(comments):}}
> <h2>Comments</h2><br /><p>
> {{for comment in comments:}}
> <p>{{=comment.author}} says <i>{{=comment.body}}</i></p>
> {{pass}}</p>
> {{else:}}
> <h2>No comments posted yet</h2>
> {{pass}}
> <h2>Post a comment</h2>
> {{=form}}
>
> Thank you very much in advance for your help.
> Ed
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---