Complete the code to import the Flask class.
from flask import [1]
The Flask class is imported from the flask module to create the app.
Complete the code to get the uploaded file from the form.
file = request.files.get('[1]')
The key used to get the uploaded file from the form is the name attribute of the file input, commonly 'file'.
Fix the error in saving the uploaded file securely.
filename = secure_filename(file.[1]) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
The uploaded file object has a 'filename' attribute that holds the original file name.
Fill both blanks to check if the request method is POST and a file is present.
if request.method == '[1]' and '[2]' in request.files:
To handle file uploads, the request method must be 'POST' and the file field name (usually 'file') must be in request.files.
Fill all three blanks to create a Flask route that accepts file uploads and saves the file.
@app.route('/upload', methods=['[1]']) def upload_file(): if request.method == '[2]' and '[3]' in request.files: file = request.files['file'] filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) return 'File uploaded successfully' return 'Upload a file'
The route must allow POST method to upload files. The request method is checked for 'POST' and the file field name is 'file'.