Last active
August 30, 2020 13:42
-
-
Save mckelvin/8340a6388a15a7c10a3916e5af9f0c26 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 python3 | |
import os | |
from flask import Flask, request, redirect, url_for | |
from werkzeug.utils import secure_filename | |
app = Flask(__name__) | |
@app.route('/') | |
def home(): | |
return """ | |
<html> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<body> | |
<form action="/stdout" method="post"> | |
<textarea id="content" name="content" cols="76"></textarea> | |
<input type="submit" name="submit" /> | |
</form> | |
</br> | |
<form method="post" action="/upload" enctype="multipart/form-data"> | |
<input type="file" name="file" /> | |
<input type="submit" value="Upload" /> | |
</form> | |
</body> | |
</html> | |
""" | |
@app.route("/stdout", methods=["GET", "POST"]) | |
def stdout(): | |
print(request.form.get("content")) | |
return redirect(url_for(".home")) | |
@app.route("/upload", methods=["POST"]) | |
def upload(): | |
file_ = request.files['file'] | |
filename = secure_filename(file_.filename) | |
save_path = os.path.join(app.config.get('UPLOAD_FOLDER', '/tmp'), filename) | |
print(f"Savd to {save_path}") | |
file_.save(save_path) | |
return redirect(url_for(".home")) | |
if __name__ == '__main__': | |
app.run("0.0.0.0", debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment