FastAPI - File Handling
Identify the error in this FastAPI endpoint for background file processing:
from fastapi import FastAPI, UploadFile, BackgroundTasks
app = FastAPI()
def process_file(file: UploadFile):
content = file.file.read()
with open(f"processed_{file.filename}", "wb") as f:
f.write(content)
@app.post("/upload")
async def upload(file: UploadFile, background_tasks: BackgroundTasks):
background_tasks.add_task(process_file, file.file.read())
return {"message": "Processing started"}