-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.py
56 lines (46 loc) · 1.78 KB
/
server.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
46
47
48
49
50
51
52
53
54
55
56
import os
count = 0
from flask import (Flask, Response, flash, redirect, render_template, request,
url_for)
from werkzeug.utils import secure_filename
UPLOAD_FOLDER = "uploads"
def createApp():
app = Flask(__name__)
app.config.from_mapping(
# https://flask.palletsprojects.com/en/2.1.x/config/ for Configuration Options
UPLOAD_FOLDER=UPLOAD_FOLDER,
SECRET_KEY="dev",
DATABASE=os.path.join(app.instance_path, "flaskr.sqlite"),
)
@app.route("/", methods=["GET", "POST"])
def home():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
print(type(request))
# If the user does not select a file, the browser submits an
# empty file without a filename.
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
flash("File Uploaded Successfully")
# return redirect(url_for('upload_file'))
return render_template("index.html")
# @app.route("/upload", methods=["GET", "POST"])
# def upload_file():
# # if request.method == "POST":
# # f = request.files["file"]
# # f.save(secure_filename(f.filename))
# # return "File uploaded successfully"
# return render_template("index.html")
return app
if __name__ == "__main__":
app = createApp()
app.debug = True
app.run()