Show images and pdf online

90 views
Skip to first unread message

Áureo Dias Neto

unread,
Dec 5, 2016, 7:11:41 AM12/5/16
to web2py-users
Hello guy's, 

I want to show uploaded photos and pdf's documments, to users, online

Example, a page show thumbnails of photos uploaded, and when user click on thumbnail, it open a full photo or pdf online

António Ramos

unread,
Dec 5, 2016, 7:39:01 AM12/5/16
to web...@googlegroups.com
i think this helps

def download():
    return response.download(request, db,attachment=False)

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Áureo Dias Neto

unread,
Dec 5, 2016, 6:56:39 PM12/5/16
to web...@googlegroups.com
It's still downloading files...

Dave S

unread,
Dec 5, 2016, 9:19:58 PM12/5/16
to web...@googlegroups.com
On Monday, December 5, 2016 at 3:56:39 PM UTC-8, Áureo Dias Neto wrote:
It's still downloading files...


Are you saying that a download request never terminates?   Can you use your browser's developer tools to see what's happening in terms of requests-responses (as shown on the network tab)?

Or are you saying it doesn't display in the page, but goes straight to saving the file?

You might also recognize Antonio's response in the example from Chapter 3 of the web2py book (in image blog):
which also displays the image on the page.

Good luck!

/dps

 
2016-12-05 10:38 GMT-02:00 António Ramos <ramst...@gmail.com>:
i think this helps

def download():
    return response.download(request, db,attachment=False)
2016-12-05 12:11 GMT+00:00 Áureo Dias Neto <aureod...@gmail.com>:
Hello guy's, 

I want to show uploaded photos and pdf's documments, to users, online

Example, a page show thumbnails of photos uploaded, and when user click on thumbnail, it open a full photo or pdf online

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

Áureo Dias Neto

unread,
Dec 5, 2016, 11:06:58 PM12/5/16
to web...@googlegroups.com
No, the function show pdf's online, but images, insiste to download it, i want to show it online

2016-12-06 0:19 GMT-02:00 Dave S <snide...@gmail.com>:
On Monday, December 5, 2016 at 3:56:39 PM UTC-8, Áureo Dias Neto wrote:
It's still downloading files...


Are you saying that a download request never terminates?   Can you use your browser's developer tools to see what's happening in terms of requests-responses (as shown on the network tab)?

You might also recognize Antonio's response in the example from Chapter 3 of the web2py book (in image blog):

To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.
Message has been deleted

Marlysson Silva

unread,
Dec 6, 2016, 8:23:05 AM12/6/16
to web2py-users
Try this in your view:

def pdf_online():
    response
.headers["Content-Type"] = "application/pdf"
   
   
return (file=path_to_file)

in template pdf_online.html :
pdf_online.html

:

{{=file}}

Dave S

unread,
Dec 6, 2016, 2:21:23 PM12/6/16
to web2py-users


On Monday, December 5, 2016 at 8:06:58 PM UTC-8, Áureo Dias Neto wrote:
No, the function show pdf's online, but images, insiste to download it, i want to show it online



Take a look at the book example (has controller and view).  Link is in the edited version of the message you replied to.
(Not sure why the unedited version was still around 2 hours later)

/dps

Massimo Di Pierro

unread,
Dec 9, 2016, 10:46:10 AM12/9/16
to web2py-users
assuming

db.define_table('mytable',Field('myfile','upload'))

and

from = SQLFORM(db.mytable)

and 

record = db.mytable(somenumber)

You can do

{{if record.myfile.endswith('.jpg'):}}
   <img src="{{=URL('download',args=record.myfile)}}"/>
{{else:}}
   <a href="{{=URL('download',args=record.myfile)}}">download</a>
{{pass}}
Reply all
Reply to author
Forward
0 new messages