I have the next python code:
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import os
PORT_NUMBER = 8080
#This class will handles any incoming request from
#the browser
class myHandler(BaseHTTPRequestHandler):
store_path = os.path.dirname(os.path.realpath(__file__)) + '\copyFile'
print store_path
# handler for the GET requests
def do_GET(self):
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
# Send the html message
self.wfile.write("Hello World !")
return
# handeler for POST request
def do_POST(self):
length = self.headers['content-length']
data = self.rfile.read(int(length))
with open(self.store_path, 'w') as fh:
fh.write(data.decode())
self.send_response(200)
try:
#Create a web server and define the handler to manage the
#incoming request
server = HTTPServer(('', PORT_NUMBER), myHandler)
print 'Started httpserver on port ' , PORT_NUMBER
#Wait forever for incoming htto requests
server.serve_forever()
except KeyboardInterrupt:
print '^C received, shutting down the web server'
server.socket.close()
I'm trying to make a simple python webserver to save files that is POSTed to a local path. I am sending the file to the server with curl
with the following line: curl -F file="myfile.txt" http://localhost:8080
The result is not as i expected:
--------------------------e6929774a41d68c0
Content-Disposition: form-data; name="file"
myfile.txt
--------------------------e6929774a41d68c0--
What can i do to fix the problem?
I checked this link but it doesnt help :(
`
– Martin Rezyne Mar 30 '15 at 16:07