app.py 933 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import os
  2. from flask import Flask, render_template, request, redirect, send_file, url_for
  3. from s3_demo import list_files, download_file, upload_file
  4. app = Flask(__name__)
  5. UPLOAD_FOLDER = "uploads"
  6. BUCKET = "insert_bucket_name_here"
  7. @app.route('/')
  8. def entry_point():
  9. return 'Hello World!'
  10. @app.route("/storage")
  11. def storage():
  12. contents = list_files(BUCKET)
  13. return render_template('storage.html', contents=contents)
  14. @app.route("/upload", methods=['POST'])
  15. def upload():
  16. if request.method == "POST":
  17. f = request.files['file']
  18. f.save(f.filename)
  19. upload_file(f"{f.filename}", BUCKET)
  20. return redirect("/storage")
  21. @app.route("/download/<filename>", methods=['GET'])
  22. def download(filename):
  23. if request.method == 'GET':
  24. output = download_file(filename, BUCKET)
  25. return send_file(output, as_attachment=True)
  26. if __name__ == '__main__':
  27. app.run(debug=True)