Skip to content

Instantly share code, notes, and snippets.

@vrootic
Created July 28, 2014 16:22
Show Gist options
  • Save vrootic/23c35174bcc854f388b1 to your computer and use it in GitHub Desktop.
Save vrootic/23c35174bcc854f388b1 to your computer and use it in GitHub Desktop.
import os
from flask import render_template, request, send_from_directory
from werkzeug.utils import secure_filename
from app import app
@app.route('/')
def index():
return render_template('index.html')
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
file = request.files['file']
if file.filename:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return render_template('index.html', filename=filename)
return render_template('index.html')
@app.route('/uploads/<path:filename>')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename, as_attachment=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment