Uploading files
Peter Mott
peter at monicol.co.uk
Tue Jan 11 07:19:35 EST 2005
Thanks for this.
Peter
"Robert Brewer" <fumanchu at amor.org> wrote in message
news:mailman.466.1105385969.22381.python-list at python.org...
Peter Mott wrote:
> If you upload a file using the cgi module is there any
> way to discover the file name that the user submitted
> as well as the file data? I've googled till I squint
> but I can't find anything.
Working example (for ASP, which uses BinaryRead to get the request
stream):
contentLength = int(env['CONTENT_LENGTH'])
content, size = request.BinaryRead(contentLength)
content = StringIO.StringIO(content)
form = cgi.FieldStorage(content, None, "", env, True)
content.close()
for key in form:
value = form[key]
try:
filename = value.filename
except AttributeError:
filename = None
if filename:
# Store filename, filedata as a tuple.
self.requestParams[key] = (filename, value.value)
else:
for subValue in form.getlist(key):
self.requestParams[key] = subValue
Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org
More information about the Python-list
mailing list