Created
August 26, 2019 11:18
-
-
Save michaelneu/8e8adbb32522c790db4439cb72229e52 to your computer and use it in GitHub Desktop.
Quickly create an HTTP upload form to drop files on your machine.
This file contains 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 werkzeug import secure_filename | |
app = Flask(__name__) | |
@app.route("/", methods=["GET"]) | |
def index(): | |
return """<!doctype html> | |
<html> | |
<body> | |
<form method="post" enctype="multipart/form-data"> | |
<input type="file" name="file"> | |
<input type="submit"> | |
</form> | |
</body> | |
</html> | |
""" | |
@app.route("/", methods=["POST"]) | |
def upload(): | |
f = request.files["file"] | |
f.save(secure_filename(f.filename)) | |
return "file uploaded" | |
if __name__ == "__main__": | |
app.run(host="0.0.0.0") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment