Bird
0
0

Which of the following is the correct way to return a file named report.pdf from a FastAPI endpoint using FileResponse?

easy📝 Syntax Q3 of 15
FastAPI - File Handling
Which of the following is the correct way to return a file named report.pdf from a FastAPI endpoint using FileResponse?
Areturn FileResponse(path='report.pdf', filename='report.pdf')
Breturn FileResponse(filename='report.pdf')
Creturn FileResponse(file='report.pdf')
Dreturn FileResponse(file_path='report.pdf', download_name='report.pdf')
Step-by-Step Solution
Solution:
  1. Step 1: Check FileResponse parameters

    FileResponse requires a path (positionally or via path= keyword) and optionally filename= keyword argument to suggest download name.
  2. Step 2: Validate options

    return FileResponse(path='report.pdf', filename='report.pdf') correctly uses path and filename parameters. return FileResponse(filename='report.pdf') misses the required path. return FileResponse(file='report.pdf') uses the wrong parameter name 'file'. return FileResponse(file_path='report.pdf', download_name='report.pdf') uses invalid parameter names.
  3. Final Answer:

    return FileResponse(path='report.pdf', filename='report.pdf') -> Option A
  4. Quick Check:

    Correct FileResponse syntax = return FileResponse(path='report.pdf', filename='report.pdf') [OK]
Quick Trick: FileResponse needs path and filename parameters correctly named [OK]
Common Mistakes:
MISTAKES
  • Using wrong parameter names like file or file_path
  • Omitting filename for download name
  • Passing file path as a keyword argument incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes