Bird
0
0

Which of the following is the correct syntax to declare a FastAPI endpoint that accepts a single file upload named 'file'?

easy📝 Syntax Q3 of 15
FastAPI - File Handling
Which of the following is the correct syntax to declare a FastAPI endpoint that accepts a single file upload named 'file'?
Aasync def upload(file: UploadFile = File(...))
Basync def upload(file: str = File(...))
Cdef upload(file: UploadFile)
Ddef upload(file: bytes = File(...))
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter type and default value

    File uploads require UploadFile type and File(...) as default to mark required.
  2. Step 2: Confirm async function and parameter syntax

    Async function with file: UploadFile = File(...) is correct syntax.
  3. Final Answer:

    async def upload(file: UploadFile = File(...)) -> Option A
  4. Quick Check:

    Correct syntax for single file upload = B [OK]
Quick Trick: Use UploadFile with File(...) default in async def [OK]
Common Mistakes:
MISTAKES
  • Using str or bytes instead of UploadFile
  • Missing File(...) default to mark required
  • Not using async def for endpoint

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes