Bird
0
0

You want to save multiple uploaded files in FastAPI and return their sizes. Which approach is best?

hard📝 component behavior Q8 of 15
FastAPI - File Handling
You want to save multiple uploaded files in FastAPI and return their sizes. Which approach is best?
ARead all files at once using a single UploadFile parameter
BUse a list of UploadFile parameters and loop to read and save each
CSave files without reading contents to get size
DUse bytes parameters instead of UploadFile for multiple files
Step-by-Step Solution
Solution:
  1. Step 1: Understand multiple file uploads

    FastAPI supports list of UploadFile to handle multiple files.
  2. Step 2: Loop through files to read and save

    Looping lets you read contents, save files, and calculate sizes individually.
  3. Final Answer:

    Use a list of UploadFile parameters and loop to read and save each -> Option B
  4. Quick Check:

    Multiple files = list of UploadFile + loop [OK]
Quick Trick: Use List[UploadFile] for multiple files [OK]
Common Mistakes:
MISTAKES
  • Trying single UploadFile for many files
  • Not reading contents before saving
  • Using bytes instead of UploadFile for multiple

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes