I am running cherrypy and a module that receives a file and I want to dump the data to disk. Instead of using the cherrypy expose and getting the file from my main cherrypy application I wanted to process it myself. I've been able to get to this
print kwargs['image']
and it dumps this to the console
FieldStorage('image', 'Diagram1.jpeg', *raw image data*)
How can I access the three variables there and use them in my program?
If I try to index them it says, Instance type not indexable.
I was able to get this out of print kwargs['image'].__dict__
{'fp': <cherrypy.wsgiserver.SizeCheckWrapper object at 0x23ba510>,
'disposition_options': {'name': 'image', 'filename': 'Diagram1.jpeg'},
'innerboundary': '',
'name': 'image',
'_FieldStorage__file': None,
'list': None,
'filename': 'Diagram1.jpeg',
'keep_blank_values': 1,
'headers': <rfc822.Message instance at 0x23c1830>,
'length': -1,
'done': 1,
'disposition': 'form-data',
'qs_on_post': None,
'strict_parsing': 0,
'file': <open file '<fdopen>',
mode 'w+b' at 0x23a1270>,
'outerboundary': '----WebKitFormBoundary5KJ5TEJBxEKAvcW1',
'type_options': {},
'type': 'image/jpeg'}
But none of it seems accessibly since it says TypeError: not indexable
your kwargs['image']
is a FieldStorage
object. The __dict__
method is a wrapper, so as you might be able to do dict(kwargs['image'])
.
dir(kwargs['image'])
was able to find the file attribute which is a file pointer which can be read like a file. Other variables as indicated abovefilename
andtype
are also of importanc - Supernovah 2012-04-05 00:34