forked from dianephan/flask-aws-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
30 lines (24 loc) · 843 Bytes
/
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
import os
from flask import Flask, render_template, request, redirect, send_file
from s3_functions import list_files, upload_file, show_image
from werkzeug.utils import secure_filename
app = Flask(__name__)
UPLOAD_FOLDER = "uploads"
BUCKET = os.environ.get('BUCKET_NAME')
@app.route("/")
def home():
contents = list_files(BUCKET)
return render_template('index.html')
@app.route("/pics")
def list():
contents = show_image(BUCKET)
return render_template('collection.html', contents=contents)
@app.route("/upload", methods=['POST'])
def upload():
if request.method == "POST":
f = request.files['file']
f.save(os.path.join(UPLOAD_FOLDER, secure_filename(f.filename)))
upload_file(f"uploads/{f.filename}", BUCKET)
return redirect("/")
if __name__ == '__main__':
app.run(debug=True)