[CherryPy]Serve dynamic binary file in cherrypy?

M

mep

Hi,
After lookup in cherrypy site and google for a while, I haven't
found any information about cherrypy how to serve dynamic binary
file(some generated charts).Is there any easy way to do this?
In cherrypy 2.0 & python 2.4
 
R

Remi Delon

mep said:
Hi,
After lookup in cherrypy site and google for a while, I haven't
found any information about cherrypy how to serve dynamic binary
file(some generated charts).Is there any easy way to do this?
In cherrypy 2.0 & python 2.4

Yes, there is an easy way: have your handler method return the binary
data, and set the Content-Type before returning the data, like this:

# class Root:
# def index(self):
# ... Generate binary data in "data" ...
# cpg.response.headerMap['Content-Type'] = 'image/gif'
# return data

Remi.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top