diff --git a/docs/patterns/fileuploads.rst b/docs/patterns/fileuploads.rst index 74cdd98b..00f44a93 100644 --- a/docs/patterns/fileuploads.rst +++ b/docs/patterns/fileuploads.rst @@ -56,7 +56,16 @@ the file and redirects the user to the URL for the uploaded file:: @app.route('/', methods=['GET', 'POST']) def upload_file(): if request.method == 'POST': + # check if the post request has the file part + if 'file' not in request.files: + flash('No file part') + return redirect(request.url) file = request.files['file'] + # if user does not select file, browser also + # submit a empty part without filename + if file.filename == '': + flash('No selected file') + 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))