Complete the code to check the file extension before upload.
if filename.endswith([1]): print("File accepted")
Only files with the .jpg extension are accepted here to reduce risk.
Complete the code to limit the maximum file size to 5MB.
if file_size [1] 5 * 1024 * 1024: print("File size is acceptable")
The file size should be less than or equal to 5MB to be accepted.
Fix the error in the code that checks for allowed MIME types.
allowed_types = ['image/png', 'image/jpeg'] if file_mime_type [1] allowed_types: print("MIME type allowed")
The in operator checks if the MIME type is in the allowed list.
Fill both blanks to safely save the uploaded file with a unique name.
import uuid unique_name = str(uuid.[1]()) + [2] + file_extension save_file(unique_name)
Using uuid4() generates a random unique ID, and "." joins the name and extension safely.
Fill all three blanks to create a dictionary comprehension filtering safe files by size and extension.
safe_files = {file: size for file, size in files.items() if file.endswith([1]) and size [2] [3]This comprehension keeps files ending with .png and size less than or equal to 5MB.
