Created
August 20, 2019 19:48
-
-
Save wpjunior/0d051e30e646f17c250003c51865239f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import logging | |
import json | |
try: | |
from urllib.parse import unquote | |
except ImportError: | |
# Python 2. | |
from urllib import unquote | |
import tornado.ioloop | |
import tornado.web | |
from tornado import options | |
class POSTHandler(tornado.web.RequestHandler): | |
def post(self): | |
file_uploaded = self.request.files['file'][0] | |
filename, content_type = file_uploaded["filename"], file_uploaded["content_type"] | |
file_body = file_uploaded["body"] | |
api_body = json.loads(self.request.body_arguments['body'][0]) | |
logging.info( | |
'POST "%s" "%s" %d bytes, metadata: %s', filename, content_type, len(file_body), json.dumps(api_body), | |
) | |
self.write("OK") | |
def make_app(): | |
return tornado.web.Application([(r"/", POSTHandler)]) | |
## example | |
## curl -XPOST 'localhost:8888/' \ | |
## -F "[email protected];type=image/png;filename=arquivo.png" \ | |
## -F 'body={"name":"Backstage", "rightsHolder": "Backstage"}' | |
if __name__ == "__main__": | |
# Tornado configures logging. | |
options.parse_command_line() | |
app = make_app() | |
app.listen(8888) | |
tornado.ioloop.IOLoop.current().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment