-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
48 lines (41 loc) · 1.49 KB
/
app.py
File metadata and controls
48 lines (41 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
from flask import Flask, request, render_template_string
from werkzeug.utils import secure_filename
# Configure from environment variables
UPLOAD_DIR = os.environ.get('UPLOAD_DIR', '/uploads')
os.makedirs(UPLOAD_DIR, exist_ok=True)
# Optional: set a maximum upload size (e.g., 16 MB by default)
# Uncomment the line below if you want to enforce file size limits.
# MAX_CONTENT_LENGTH = int(os.environ.get('MAX_CONTENT_LENGTH', 16 * 1024 * 1024))
DEBUG_MODE = os.environ.get('DEBUG', 'False').lower() in ['true', '1', 'yes']
FLASK_PORT = 80
app = Flask(__name__)
# If you uncomment the MAX_CONTENT_LENGTH above, set it in the app config:
# app.config['MAX_CONTENT_LENGTH'] = MAX_CONTENT_LENGTH
# Basic HTML page for file upload
HTML = '''
<!doctype html>
<html>
<head><title>One Way File Drop</title></head>
<body>
<h1>Upload a File</h1>
<form method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
</body>
</html>
'''
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
file = request.files.get('file')
if file:
filename = secure_filename(file.filename)
filepath = os.path.join(UPLOAD_DIR, filename)
file.save(filepath)
# Set file permissions: owner read/write only
os.chmod(filepath, 0o600)
return HTML
if __name__ == '__main__':
app.run(host='0.0.0.0', port=FLASK_PORT, debug=DEBUG_MODE)