Multipart data in CherryPy
I've spent a little while trying to get CherryPy 3.2 to handle multipart/form-encoded data in a useful fashion. That is, I need access to the Content-Type of each part.
By default, it passes each part as a named string argument to your handler function.
I finally found the correct incantations to get cherrypy.request.body.parts to contain the Entity instances, each of which has a .content_type, .name, etc. From there I can constitute a kind of sane arglist.
# Somewhere early on
def multipart_tool():
cherrypy.request.body.processors[u'multipart/form-data'] = cherrypy._cpreqbody.process_multipart
cherrypy.tools.multipart_tool = cherrypy.Tool('on_start_resource', multipart_tool)
# In your handler class:
class Foo(object):
_cp_config = {'tools.multipart_tool.on': True}
The advice on the CherryPy wiki suggests setting the "multipart" processor, which is overruled by the multipart/form-data processor. Pah.
The more I use Python, the more I find it totally unsuitable for getting things done.
Posted at 2009-09-28 21:51:00 by Richard Newman • Link to Multipart data in …
