upload - Python CGI - How can I get uploaded file in TCP server? -


i made tcp server this

serverport = 8181 serversocket = socket(af_inet, sock_stream) serversocket.bind(('', serverport)) serversocket.listen(5) 

and can receive user's login data this

elif path == '/login':         header, query = message.split(b'\r\n\r\n')         fp = io.bytesio(query)         form = cgi.fieldstorage(fp, environ={'request_method':'post'})          connectionsocket.send(b'http/1.1 200 ok\r\n')         connectionsocket.send(b'content-type: text/html\r\n\r\n')         connectionsocket.send('<p>hello {}!</p>'.format(form.getvalue('id')).encode('utf-8')) 

but can't receive multipart upload data!!t^t

i wrote html upload file

<html> <body>  <form enctype="multipart/form-data" action="http://127.0.0.1:8181/upload" method=post>     file process: <input name="file" type="file">     <input type="submit" value="send file"> </form>  </body> </html> 

how can receive file , save that?

i know using http server way problem

but shoud using tcp server that...

please me! cant solve problem...t^t

file uploads use different content type; post uses application/x-www-form-urlencoded, file upload requires form use multipart/form-data.

the cgi.fieldstorage class sniff cgi environment variables, not using cgi here, parsing @ lowest level. you'll have pass in content_type header here:

form = cgi.fieldstorage(fp, environ={     'request_method':'post', 'content_type': 'multipart/form-data'}) 

ideally, header parsed incoming headers, of course.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -