Bird
0
0

What is the issue with this FastAPI endpoint for multiple file uploads?

medium📝 Debug Q6 of 15
FastAPI - File Handling
What is the issue with this FastAPI endpoint for multiple file uploads?
from fastapi import FastAPI, UploadFile
from typing import List

app = FastAPI()

@app.post('/upload')
async def upload(files: List[UploadFile]):
    return {'count': len(files)}
AUsing async def instead of def
BMissing File(...) dependency in the parameter declaration
CNot importing File from fastapi
DReturning a dictionary instead of JSONResponse
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter declaration

    The parameter files is typed as List[UploadFile] but lacks File(...) which is required to tell FastAPI to expect files.
  2. Step 2: Understand File(...) role

    File(...) is a special dependency that marks the parameter as a file upload field.
  3. Final Answer:

    Missing File(...) dependency in the parameter declaration -> Option B
  4. Quick Check:

    List[UploadFile] must be combined with File(...) [OK]
Quick Trick: Always add File(...) when using List[UploadFile] [OK]
Common Mistakes:
MISTAKES
  • Forgetting File(...) causes FastAPI to treat input as JSON
  • Assuming async def is incorrect (it's allowed)
  • Thinking return type must be JSONResponse explicitly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes