commit 124e327a6e12266d5b314d78a7dd7cae00450c24 Author: bretello Date: Fri Jun 14 17:39:50 2024 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/app.py b/app.py new file mode 100644 index 0000000..742dfd7 --- /dev/null +++ b/app.py @@ -0,0 +1,47 @@ +import os +from flask import Flask + +from flask import request, render_template + +app = Flask( + __name__, + # static_url_path="./", + static_folder="static", + template_folder="templates", +) +os.makedirs("uploads", exist_ok=True) + + +@app.route("/") +def upload_form(): + return render_template( + "upload.html", + title="Upload your shit here", + ) + + +@app.route("/upload", methods=["POST"]) +def upload_file(): + if "file" not in request.files: + return "No file part" + + file = request.files["file"] + if file.filename == "": + return "No selected file" + + if not file: + return "No file?" + + save_path = os.path.join("uploads", file.filename) + assert not os.path.exists(save_path) + + try: + file.save(save_path) + except Exception as exc: + return f"fail: {exc=}" + + return "File uploaded successfully" + + +if __name__ == "__main__": + app.run() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e4a286c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +flask +gunicorn diff --git a/templates/upload.html b/templates/upload.html new file mode 100644 index 0000000..f3a557d --- /dev/null +++ b/templates/upload.html @@ -0,0 +1,10 @@ + + + {{ title }} + + +
+ + +
+