-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathapp.py
43 lines (27 loc) · 933 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
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
from flask import Flask, render_template, request, redirect, send_file, url_for
from s3_demo import list_files, download_file, upload_file
app = Flask(__name__)
UPLOAD_FOLDER = "uploads"
BUCKET = "insert_bucket_name_here"
@app.route('/')
def entry_point():
return 'Hello World!'
@app.route("/storage")
def storage():
contents = list_files(BUCKET)
return render_template('storage.html', contents=contents)
@app.route("/upload", methods=['POST'])
def upload():
if request.method == "POST":
f = request.files['file']
f.save(f.filename)
upload_file(f"{f.filename}", BUCKET)
return redirect("/storage")
@app.route("/download/<filename>", methods=['GET'])
def download(filename):
if request.method == 'GET':
output = download_file(filename, BUCKET)
return send_file(output, as_attachment=True)
if __name__ == '__main__':
app.run(debug=True)