Skip to content

Instantly share code, notes, and snippets.

@michaelneu
Created August 26, 2019 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelneu/8e8adbb32522c790db4439cb72229e52 to your computer and use it in GitHub Desktop.
Save michaelneu/8e8adbb32522c790db4439cb72229e52 to your computer and use it in GitHub Desktop.
Quickly create an HTTP upload form to drop files on your machine.
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