Skip to content

Instantly share code, notes, and snippets.

@johanforssell
Last active January 2, 2016 02:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johanforssell/8237848 to your computer and use it in GitHub Desktop.
Save johanforssell/8237848 to your computer and use it in GitHub Desktop.
Simple web server which accepts chunked uploads and responds with a dummy json
#!/usr/bin/python
import time
import BaseHTTPServer
import json
from pprint import pprint
HOST_NAME = '192.168.1.89'
PORT_NUMBER = 9494
media_results = {
"media_results": [
{
"filename": "4711.jpg",
"image": {
"media_id": "/public/media/ad/12345678",
"base_url": "http://localhost/images/",
"media_path": "12/12345678.jpg",
"height": 480,
"width": 640
}
}
],
"media_statistics": {
"failed_process": 0,
"failed_store": 0,
"ignored": 0,
"ok": 1,
"processed": 1
}
}
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(s):
"""Respond to a GET request by doing nothing at all"""
s.send_response(200)
def do_POST(s):
"""Respond to a POST request."""
s.send_response(200)
s.send_header("Content-type", "application/json")
s.end_headers()
json.dump(media_results, s.wfile)
pprint(vars(s.headers))
print('')
print('')
print('########################################################################')
if __name__ == '__main__':
server_class = BaseHTTPServer.HTTPServer
httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler)
print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)
@johanforssell
Copy link
Author

curl \
-H "Transfer-Encoding: chunked" \
-F "image=@/Users/johanforsell/Pictures/iPhoto Library.photolibrary/Masters/2013/10/25/20131025-131505/IMG_3465.JPG" \
http://192.168.1.89:9494/public/media/ad

I would also need -H "Expect: " \ to mimic how NSURLSession sends things, but it generates an error when used with curl for some reason

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment