Last active
May 22, 2016 19:18
-
-
Save zsteva/5f13a5fabd7a7f6d22f7f84a8d1f4859 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
| from flask import Flask, request | |
| from flask import request | |
| import logging | |
| import tempfile, os, md5, sys | |
| app = Flask(__name__) | |
| app.logger.addHandler(logging.StreamHandler(stream=sys.stderr)) | |
| @app.route("/") | |
| def hello(): | |
| return "root" | |
| @app.route('/upload', methods=['POST']) | |
| def upload(): | |
| tmpfile = tempfile.mkstemp('.bin', 'file', '/tmp') | |
| md5sum = md5.new() | |
| file_size = 0 | |
| fd = os.fdopen(tmpfile[0], 'wb') | |
| while True: | |
| buf = request.stream.read(1024) | |
| if len(buf) > 0: | |
| md5sum.update(buf) | |
| file_size += len(buf) | |
| fd.write(buf) | |
| else: | |
| break | |
| fd.close() | |
| return("SIZE " + str(file_size) + "\n" + | |
| "MD5 " + md5sum.hexdigest() + "\n" + | |
| "FILE " + tmpfile[1] + "\n") | |
| if __name__ == "__main__": | |
| app.run(host='0.0.0.0', port=8080) |
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
| > ls -la ~/file1000.bin ; md5sum ~/file1000.bin ; curl -X POST -T ~/file1000.bin http://localhost:8080/upload | |
| -rw-r--r-- 1 zsteva zsteva 1048576000 May 22 20:28 /home/zsteva/file1000.bin | |
| e07d262b76d2af71b3f53783870cb44f /home/zsteva/file1000.bin | |
| SIZE 1048576000 | |
| MD5 e07d262b76d2af71b3f53783870cb44f | |
| FILE /tmp/filek9vRSW.bin | |
| > md5sum /tmp/filek9vRSW.bin | |
| e07d262b76d2af71b3f53783870cb44f /tmp/filek9vRSW.bin | |
| > |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
