-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
55 lines (28 loc) · 1.11 KB
/
app.py
File metadata and controls
55 lines (28 loc) · 1.11 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
49
50
51
52
53
54
55
from flask import Flask, request, render_template, redirect, url_for, send_from_directory
import os
app = Flask(__name__)
# Configure the upload folder and ensure it exists
UPLOAD_FOLDER = os.path.join(os.getcwd(), 'uploads')
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/')
def index():
# Show a simple HTML form to upload files and list uploaded images.
images = os.listdir(app.config['UPLOAD_FOLDER'])
return render_template('index.html', images=images)
@app.route('/upload', methods=['POST'])
def upload_image():
if 'image' not in request.files:
return "No file part", 400
file = request.files['image']
if file.filename == '':
return "No selected file", 400
# Save the file
file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
return redirect(url_for('index'))
@app.route('/uploads/<filename>')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)