Skip to content

Instantly share code, notes, and snippets.

@viveksb007
Created March 22, 2018 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viveksb007/63000de701487e762ee2c170f309342f to your computer and use it in GitHub Desktop.
Save viveksb007/63000de701487e762ee2c170f309342f to your computer and use it in GitHub Desktop.
from flask import Flask, request, redirect, url_for, render_template, send_from_directory
from werkzeug.utils import secure_filename
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
if 'file' not in request.files:
print('No file attached in request')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
print('No file selected')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
process_file(os.path.join(app.config['UPLOAD_FOLDER'], filename), filename)
return redirect(url_for('uploaded_file', filename=filename))
return render_template('index.html')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment