flask form input file code example
Example 1: create internal etl for people to upload data with python and flask
from flask import Flask, render_template, requestfrom werkzeug import secure_filenameapp = Flask(__name__)@app.route('/upload')def upload_file(): return render_template('upload.html') @app.route('/uploader', methods = ['GET', 'POST'])def upload_file(): if request.method == 'POST': f = request.files['file'] f.save(secure_filename(f.filename)) return 'file uploaded successfully' if __name__ == '__main__': app.run(debug = True)
Example 2: flask upload
import os
from flask import Flask, flash, request, redirect, url_for
from werkzeug.utils import secure_filename
UPLOAD_FOLDER = '/path/to/the/uploads'
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER