Recall & Review
beginner
What Flask function is commonly used to serve uploaded files to users?
The
send_from_directory() function is used to safely serve uploaded files from a specific folder to users.Click to reveal answer
intermediate
Why should you avoid serving uploaded files directly from the upload folder without precautions?
Serving files directly can expose sensitive files or allow execution of harmful files. Using
send_from_directory() helps control access and prevents security risks.Click to reveal answer
beginner
How do you specify the folder from which Flask serves uploaded files?
You pass the folder path as the first argument to
send_from_directory(), for example: send_from_directory('uploads', filename).Click to reveal answer
beginner
What HTTP method is typically used when a user requests to download or view an uploaded file?
The GET method is used because the user is requesting to retrieve and view or download the file.
Click to reveal answer
beginner
What is a simple Flask route example to serve an uploaded file named
filename from the uploads folder?<pre>from flask import send_from_directory
@app.route('/uploads/<filename>')
def uploaded_file(filename):
return send_from_directory('uploads', filename)</pre>Click to reveal answer
Which Flask function should you use to serve a file from a specific folder?
✗ Incorrect
send_from_directory() is designed to serve files from a folder safely.What is the main security reason to use
send_from_directory() instead of serving files directly?✗ Incorrect
send_from_directory() helps prevent unauthorized access by controlling which files are served.In Flask, which HTTP method is used to request an uploaded file for download or viewing?
✗ Incorrect
GET is used to retrieve resources like files.
What argument do you pass first to
send_from_directory()?✗ Incorrect
The first argument is the folder path where the file is located.
Which of these is a correct Flask route to serve a file named
filename from the uploads folder?✗ Incorrect
Option A correctly uses
send_from_directory() with the folder and filename.Explain how to serve an uploaded file safely in Flask and why it is important.
Think about how Flask controls file access and protects the server.
You got /4 concepts.
Describe the steps to create a Flask route that allows users to download files they uploaded.
Focus on the route setup and the function used to send files.
You got /4 concepts.