By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,818 Members | 1,347 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,818 IT Pros & Developers. It's quick & easy.

CGI, FieldStorage and Filename

P: n/a

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 : be**
Cenix Website :

Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.