On Tuesday, May 28, 2019 at 11:00:42 PM UTC-7, Quang Lam wrote:
>
> Hi, i have a problem to display the CSV file stored in the table.
>
> the code below is in controller
>
> def view_performance():
> files = db.Pass_Configuration(request.args(0, cast=int)) or
> redirect(URL('index')) // get the ID of Pass_Configuration table form the
> URL
> return dict(files=files)
>
> def download():
> return response.download(request, db) //download function
>
>
> the code in the View as follows
>
> {{extend 'layout.html'}}
> <h1>{{='Performance'}}</h1><br>
> src="{{=URL('download', args=files.PerformanceFile)}}"
>
>
This will indeed display the path.
> i know i get the path to the file right but somehow it does not display
> the CSV file. it just displays the file path and nothing else. i know i am
> missing something but could not figure out
> could you please help me to point out what the mistake i have and how to
> fix it. thanks
>
I know you will need to set the content type header (I do it in my
controller function). You may also need to stream the file, as I do for a
picture
filedata=open(dst,"rb").read()
response.headers['Content-Type']='image/jpeg'
response.headers['Content-Length']=imstat.st_size
return response.stream(cStringIO.StringIO(filedata))
Appadmin.py, though, only sets the content type and then returns a string
(specifically the rows of the db query).
If you were returning a PDF, I think you're back to streaming.
/dps
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/4073c428-1d79-402e-926f-4a5076556976%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.