Skip to content
Myr

be consistent with app.config['UPLOAD_FOLDER']

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Felix Hummel · committed by Armin Ronacher · parent 2866ccd · Browse files · 1 file+3 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>

Diff stats

1 file+3 added−2 removed

  • other:+3 added−2 removed

1 file+3 added−2 removed

modified:docs/patterns/fileuploads.rst+3 added-2 removed
26 unmodified lines
27 UPLOAD_FOLDER = '/path/to/the/uploads'28 ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])2930 app = Flask(__name__)31 app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER3233So first we need a couple of imports. Most should be straightforward, the34:func:`werkzeug.secure_filename` is explained a little bit later. The35`UPLOAD_FOLDER` is where we will store the uploaded files and the
22 unmodified lines
58 if request.method == 'POST':59 file = request.files['file']60 if file and allowed_file(file.filename):61 filename = secure_filename(file.filename)61 file.save(os.path.join(UPLOAD_FOLDER, filename))62 file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))63 return redirect(url_for('uploaded_file',64 filename=filename))65 return '''66 <!doctype html>
49 unmodified lines
116 from werkzeug import SharedDataMiddleware117 app.add_url_rule('/uploads/<filename>', 'uploaded_file',118 build_only=True)119 app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {119 '/uploads': UPLOAD_FOLDER120 '/uploads': app.config['UPLOAD_FOLDER']121 })122123If you now run the application everything should work as expected.124
57 unmodified lines