我正在尝试通过html表单上传图像到我的python套接字。 表格是:
<form name="image-upload" method="post" action="" enctype="multipart/form- data">
<input type="file" name="image">
<input type="submit" name="submit" value="submit">
</form>
如何通过http套接字在我的python服务器中访问此图像?
服务器将是这样的,它将接收图像,对其进行一些处理并根据该图像返回响应。
HOST, PORT = '', 8888
my_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
my_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
my_socket.bind((HOST, PORT))
my_socket.listen(1)
while True:
client_connection, client_address = my_socket.accept()
request = client_connection.recv(1024)
#here I will have code to get image
#processing on image
response = "Image received"
http_response = "HTTP/1.1 200 OK\n"+"Content-Type: text/html\n"+"\n"+"<html><body><h1>"+response+"</h1></body></html>\n"
client_connection.sendall(http_response)
client_connection.close()