Guest User

Untitled

a guest
Oct 21st, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. from flask import Flask, request, jsonify, render_template, redirect, url_for
  2. from werkzeug import secure_filename
  3. import os
  4.  
  5. app = Flask(__name__)
  6. app.config["UPLOAD_FOLDER"] = "images/" #this specifies the upload path
  7.  
  8. @app.route("/", methods = ["GET", "POST"])
  9. def api_home():
  10. if (request.method == "POST"):
  11. image_name = request.form["image_name"] #get the name although it is useless for this example
  12. file = request.files["image_file"] #get the file
  13. filename = secure_filename(file.filename) # get the secure file name.
  14. #
  15. file.save(os.path.join(app.config["UPLOAD_FOLDER"], filename))
  16. return redirect(url_for("api_home",filename=filename))
  17. else:
  18. return render_template("index.html")
  19.  
  20. if (__name__ == "__main__"):
  21. app.run(debug=True)
Add Comment
Please, Sign In to add comment