mirror of
https://github.com/ilri/csv-metadata-quality-web.git
synced 2024-11-26 08:28:19 +01:00
Alan Orth
d204c23b93
Creating and uploading to an "uploads" directory works locally, but on Google App Engine I get an HTTP 500. Let's try uploading to /tmp.
34 lines
858 B
Python
34 lines
858 B
Python
import os
|
|
|
|
from flask import Flask, abort, redirect, render_template, request, url_for
|
|
from werkzeug.utils import secure_filename
|
|
|
|
app = Flask(__name__)
|
|
app.config["MAX_CONTENT_LENGTH"] = 1024 * 1024
|
|
app.config["UPLOAD_EXTENSIONS"] = [".csv"]
|
|
app.config["UPLOAD_PATH"] = "/tmp"
|
|
|
|
|
|
@app.route("/")
|
|
def index():
|
|
return render_template("index.html")
|
|
|
|
|
|
@app.route("/", methods=["POST"])
|
|
def upload_file():
|
|
uploaded_file = request.files["file"]
|
|
filename = secure_filename(uploaded_file.filename)
|
|
|
|
if filename != "":
|
|
file_ext = os.path.splitext(filename)[1]
|
|
if file_ext not in app.config["UPLOAD_EXTENSIONS"]:
|
|
abort(400)
|
|
|
|
uploaded_file.save(os.path.join(app.config["UPLOAD_PATH"], filename))
|
|
|
|
return redirect(url_for("index"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host="127.0.0.1", port=8080, debug=True)
|