Whenever I try to hit a POST endpoint (running on a Docker instance) that takes in an UploadFile as an argument the request never completes. And yet everything works fine when I run the backend code regularly on my machine. Gen AI suggests that it’s a an issue with Docker configuration or file permissions. I am unsure of where to go from here.
I am running FastAPI with CORS middleware and I’m trying to hit this endpoint:
@app.post("/echo")
async def echo(file: UploadFile = File(...)):
print('print here')
logger.info('in here')
try:
content = await file.read()
logger.info(f"Received file: {file.filename}, size: {len(content)} bytes")
return JSONResponse(content={"message": f"Received file of size {len(content)} bytes"})
except asyncio.TimeoutError:
logger.error("Request timed out while reading file")
raise HTTPException(status_code=408, detail="Request timeout while reading file")
except Exception as e:
logger.error(f"Error in echo endpoint: {str(e)}", exc_info=True)
raise HTTPException(status_code=500, detail=str(e))
And yet nothing happens, neither the print nor the log executes. No exceptions execute either. I’ve tried with different file formats too. Postman gives me a ‘Sending request’ that never stops.