-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
45 lines (36 loc) · 1.46 KB
/
app.py
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
from flask import Flask, render_template, request
from werkzeug.utils import secure_filename
import os, flask
cwd = os.getcwd()
upload_folder = os.path.join(cwd,'public')
app = Flask(__name__)
# app.config['UPLOAD_FOLDER'] = upload_folder
@app.route('/status')
def status():
return("The Public Server for plugin testing is up and running")
@app.route('/upload')
def upload_file_template():
return render_template('upload.html')
@app.route('/file_list')
def file_list():
f_list = os.listdir(upload_folder)
return render_template('file_list.html', f_list = f_list)
@app.route('/uploader', methods = ['POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
f.save(os.path.join(upload_folder, secure_filename(f.filename)))
return render_template('upload_success.html', file_uploaded=secure_filename(f.filename))
@app.route('/delete/<file_name>')
def delete(file_name):
try:
os.remove(os.path.join(upload_folder, secure_filename(file_name)))
return render_template('file_deleted.html', file_name=secure_filename(file_name))
except:
return render_template('Static_File_Not_Found.html', file_name=secure_filename(file_name)), 404
@app.route('/download/<file_name>')
def download(file_name):
try:
return flask.send_from_directory(upload_folder, secure_filename(file_name))
except:
return render_template('Static_File_Not_Found.html', file_name=secure_filename(file_name)), 404