Есть форма заливки файла на сервер:
<form method='POST' enctype='multipart/form-data' action='http://localhost/index.html'>
File to upload: <input type=file name=upfile>
<br><input type=submit value=Upload>
Метод сервера do_POST:
def do_POST(self):
global rootnode
try:
ctype, pdict = cgi.parse_header(self.headers.get('content-type'))
if ctype == 'multipart/form-data':
query = cgi.parse_multipart(self.rfile, pdict)
self.send_response(301)
self.end_headers()
upfilecontent = query.get('upfile')
print('filecontent:', upfilecontent[0])
outstring = '<html><body>Content of the uploaded file: ' + upfilecontent[0] + '<br><a href="http://localhost:80/index.html">Back to the main page</a></body></html>'
self.wfile.write(bytearray(str(outstring).encode(encoding='utf_8', errors='strict')))
except Exception as e:
print(e)
Содержимое файла прочитано. Но, собственно, никак не могу достать имя залитого юзером файла (например, чтобы на сервере создать файл с таким же именем). Просто нет идей, где бы оно могло храниться…