CGI, FieldStorage and Filename

Neil Benn benn at
Wed Mar 30 20:56:14 CEST 2005


          I'm writing a simple cgi script and want to be able to access 
the filename in a FieldStorage file instance.  I have successfully 
manmaged to access the file as a 'file-like object' by using the simple 
code of :

objInFile = objForm['DataFile'].file

    I can easily read through this data and get all the information out 
as I need - sorted!!  However, when I attempt to access the filename 
attribute of this using :

print 'Content-Disposition: attachment; filename="' + 
os.path.split(objForm['DataFile'].filename)[0] + '_reformatted.txt"'

    I get None back for the filename.  So I dumped the content of the 
objForm['DataFile'] to stdout to see what it contains :

print objForm['DataFile']

I got back this :

FieldStorage('DataFile', 'MOAF_10-12_fin_2.txt', 
'Project\tJob\tBarcode\tPlate set <blaahh, blaaahh, blahh>)

    As you can see, when __str__ is called, the FieldStorage is 
displaying the name of the client side file - so it knows what it is, 
however when I call .filename on it, I get None.  I don;t get what is 
happening here - has anyone else seen this and/or knows what I'm doing 

    If so then all and any help would be much appreciated.




Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 46

Tel : +49 (0)351 4173 154
e-mail : benn at
Cenix Website :

More information about the Python-list mailing list