0
0
Flaskframework~10 mins

Serving uploaded files in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the function used to send files in Flask.

Flask
from flask import Flask, [1]
Drag options to blanks, or click blank then click option'
Asend_file
Brender_template
Crequest
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'render_template' instead of 'send_file'.
Forgetting to import 'send_file' at all.
2fill in blank
medium

Complete the route function to send a file named 'example.txt' from the 'uploads' folder.

Flask
from flask import send_file

@app.route('/download')
def download():
    return send_file('[1]')
Drag options to blanks, or click blank then click option'
A'static/example.txt'
B'example.txt'
C'uploads/example.txt'
D'/example.txt'
Attempts:
3 left
💡 Hint
Common Mistakes
Using just the filename without folder path.
Using the wrong folder like 'static'.
3fill in blank
hard

Fix the error in the code to correctly send a file with a custom download name.

Flask
return send_file('uploads/report.pdf', [1]='monthly_report.pdf')
Drag options to blanks, or click blank then click option'
Afile_name
Bfilename
Cattachment_filename
Ddownload_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using the old argument 'attachment_filename' which is deprecated.
Using incorrect argument names like 'filename' or 'file_name'.
4fill in blank
hard

Fill both blanks to send a file as an attachment with the correct MIME type.

Flask
return send_file('uploads/image.png', [1]=True, [2]='image/png')
Drag options to blanks, or click blank then click option'
Aas_attachment
Bmimetype
Cdownload_name
Dattachment
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'attachment' instead of 'as_attachment'.
Confusing 'mimetype' with 'download_name'.
5fill in blank
hard

Fill all three blanks to serve an uploaded file securely using 'send_from_directory'.

Flask
from flask import send_from_directory

@app.route('/uploads/<filename>')
def uploaded_file(filename):
    return send_from_directory([1], [2], [3]=True)
Drag options to blanks, or click blank then click option'
A'uploads'
Bfilename
Cas_attachment
D'static'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'static' folder instead of 'uploads'.
Passing filename as a string instead of variable.
Omitting 'as_attachment=True' causing inline display.