[CherryPy]Serve dynamic binary file in cherrypy?

Remi Delon remi at cherrypy.org
Wed Mar 9 12:17:12 EST 2005


"mep" <mep_ at 163.com> wrote in message news:<397vt5F5qqvrkU1 at individual.net>...
> 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.



More information about the Python-list mailing list