Recall & Review
beginner
What is the purpose of allowed file types validation in Flask?
It ensures that only files with specific extensions (like .jpg, .png) are accepted for upload, improving security and preventing unwanted file types.
Click to reveal answer
beginner
How do you define allowed file extensions in a Flask app?
You create a set of allowed extensions, for example:
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}, and check uploaded files against this set.Click to reveal answer
beginner
What Flask method helps to check if a file has an allowed extension?
A common method is to write a function like
allowed_file(filename) that returns True if the file extension is in the allowed set.Click to reveal answer
intermediate
Why should you check the file extension instead of just trusting the file's MIME type?
File extensions are easier to check and prevent many unwanted files. MIME types can be spoofed or missing, so extension checking adds a simple, effective layer of security.
Click to reveal answer
beginner
What happens if a user uploads a file with a disallowed extension in Flask?
The app should reject the file upload, often by returning an error message or redirecting the user, preventing the file from being saved or processed.
Click to reveal answer
Which Python data structure is best for storing allowed file extensions in Flask?
✗ Incorrect
A set allows fast membership checks and avoids duplicates, making it ideal for allowed file extensions.
What does the function
allowed_file(filename) typically check?✗ Incorrect
The function checks if the file extension matches one of the allowed types.
Why is it important to validate file types on the server side in Flask?
✗ Incorrect
Server-side validation protects the app from harmful files regardless of client behavior.
Which of these extensions would be allowed if
ALLOWED_EXTENSIONS = {'png', 'jpg'}?✗ Incorrect
Only files with .png or .jpg extensions are allowed; photo.png matches.
What should your Flask app do if a file with a disallowed extension is uploaded?
✗ Incorrect
Rejecting and notifying the user prevents unwanted files and informs them of the issue.
Explain how to implement allowed file types validation in a Flask app.
Think about checking the file name's ending and comparing it to a list.
You got /4 concepts.
Why is allowed file types validation important for web applications handling uploads?
Consider what could happen if any file type was accepted.
You got /4 concepts.