Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, request, jsonify, render_template, redirect, url_for
- from werkzeug import secure_filename
- import os
- app = Flask(__name__)
- app.config["UPLOAD_FOLDER"] = "images/" #this specifies the upload path
- @app.route("/", methods = ["GET", "POST"])
- def api_home():
- if (request.method == "POST"):
- image_name = request.form["image_name"] #get the name although it is useless for this example
- file = request.files["image_file"] #get the file
- filename = secure_filename(file.filename) # get the secure file name.
- #
- file.save(os.path.join(app.config["UPLOAD_FOLDER"], filename))
- return redirect(url_for("api_home",filename=filename))
- else:
- return render_template("index.html")
- if (__name__ == "__main__"):
- app.run(debug=True)
Add Comment
Please, Sign In to add comment