Complete the code to import the FastAPI class.
from fastapi import [1] app = [1]()
The FastAPI class is imported to create the app instance.
Complete the code to define a POST endpoint that accepts a file upload.
@app.post("/upload") async def upload_file(file: [1]): content = await file.read() return {"size": len(content)}
UploadFile is used in FastAPI to handle file uploads asynchronously.
Fix the error in the import statement to handle file uploads.
from fastapi import [1] from fastapi import UploadFile, File
FastAPI must be imported to create the app instance; UploadFile and File are imported separately.
Fill both blanks to save the uploaded file content to disk.
async def save_file(file: UploadFile): content = await file.[1]() with open("uploaded_file", [2]) as f: f.write(content)
We read the file content asynchronously, then open a file in binary write mode to save it.
Fill all three blanks to create a FastAPI endpoint that saves an uploaded file and returns its size.
@app.post("/save") async def save_upload(file: [1] = [2](...)): content = await file.[3]() with open("saved_file", "wb") as f: f.write(content) return {"size": len(content)}
The endpoint uses UploadFile type with File() to accept uploads, reads content asynchronously, saves it, and returns size.
