initial commit

This commit is contained in:
bretello 2024-06-14 17:39:50 +02:00
commit 124e327a6e
Signed by: brethil
GPG Key ID: 876AAC6290170FE7
4 changed files with 60 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__

47
app.py Normal file
View File

@ -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()

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
flask
gunicorn

10
templates/upload.html Normal file
View File

@ -0,0 +1,10 @@
<html>
<head>
<title>{{ title }}</title>
</head>
<form action="/upload" method="POST" enctype="multipart/form-data">
<input type="file" name="file" />
<button type="submit">Upload</button>
</form>
</html>