Skip to content

Instantly share code, notes, and snippets.

@michaelneu

michaelneu/upload.py

Created Aug 26, 2019
Embed
What would you like to do?
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