POST method, CGI and file transfer

Michael Foord fuzzyman at gmail.com
Sat Sep 4 14:39:50 EDT 2004


Another http question.
First one is simple - if a POST is made *to* a CGI with file uplaods
then you can get a FieldStorage with list values - each entry in the
list being a file. Two questions about this :
1) Is this the only situation you'll get list values posted to a CGI ?
If you have a list value in your FieldStorage instance can you be sure
that it's files ?
2) If a post is made of 1 file will it still be a list ? (jsut with a
single entry)

Admittedly the second one I could actually try... :-)

More complicated - I want to proxy the file posts, i.e. extract them
from the FieldStorage and re-encode them to make another post from the
CGI. How do you encode multipart file posts - I couldn't see it
obviously from teh standard libraries. For ordinary data I would use
urllib.urlencode.

I saw one solution at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306 but
this uses httplib and makes the post. I would *much* rather (if
possible) encode the files as headers in a Request object and use
urllib2 to make the post.

MANY TIA

Regards,

Fuzzy

http://www.voidspace.org.uk/atlantibots/pythonutils.html



More information about the Python-list mailing list