ChandimaPrabath commited on
Commit
f7ae17e
·
verified ·
1 Parent(s): 4bdd653

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify, render_template
2
+ import os
3
+
4
+ app = Flask(__name__)
5
+ DOWNLOADS_PATH = './downloads' # Adjust if necessary
6
+
7
+ @app.route('/')
8
+ def home():
9
+ return render_template('index.html')
10
+
11
+ @app.route('/list-directories', methods=['GET'])
12
+ def list_directories():
13
+ directories = [d for d in os.listdir(DOWNLOADS_PATH)
14
+ if os.path.isdir(os.path.join(DOWNLOADS_PATH, d))]
15
+ return jsonify(directories)
16
+
17
+ @app.route('/upload', methods=['POST'])
18
+ def upload_file():
19
+ if 'file' not in request.files:
20
+ return 'No file part', 400
21
+ file = request.files['file']
22
+ if file.filename == '':
23
+ return 'No selected file', 400
24
+ if file:
25
+ directory = request.form.get('directory')
26
+ filepath = os.path.join(DOWNLOADS_PATH, directory, file.filename)
27
+ file.save(filepath)
28
+ return 'File uploaded successfully', 200
29
+
30
+ if __name__ == '__main__':
31
+ app.run(debug=True, host='0.0.0.0', port=7860)