[Python] Timeout error when uploading large file in FastAPI

Discussão em 'Python' iniciado por Stack, Fevereiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    I have a FastAPI function that receives a file, saves it locally, untars it and pushes the untarred image into an artifactory location. For some reason, larger files, or sometimes smaller files, get timed out, while uploading with a 200 response. I seem to follow all the suggestions like nginx as well but no luck!

    @router.post("/upload_container")
    async def post_container(file: UploadFile = File(), new_container_image: str = Form(), new_tag: str = Form()):
    if file.content_type != "application/x-tar":
    raise HTTPException(status_code=400, detail="Can only accept tarred version of Docker file")
    file_path = str(str(uuid.uuid4()).split("-")[1]) + ".tar"
    async with aiofiles.open(file_path, "wb") as out_file:
    while content := await file.read(1024): # async read chunk
    await out_file.write(content) # async write chunk
    file_path = str(os.path.abspath(os.path.join(os.getcwd(), file_path)))
    command = "podman load --input {}".format(file_path)
    result = subprocess.run(split(command), stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
    if result.returncode != 0:
    return {"filename": file.filename, "details": result.stderr, "Error": {" failed to unwrap"}}
    tagged_image = str(str(result.stdout).split("\n")[0]).split("Loaded image(s):")[1]
    if os.path.exists(file_path):
    os.remove(file_path)
    if tagandpull(tagged_image, new_container_image, new_tag) != True:
    return {"message": "Unable to push the image", "image_name": f"{file.filename}"}
    return {
    "filename": file.filename,
    "Details": {
    "new_url": "artifactorylocation.cloud.com/"
    + config_data.output["repos"]["local"]["deploy_repo"]
    + "/"
    + new_container_image,
    "new_tag": new_tag,
    },
    }


    Here is my nginx annotation.

    annotations: {
    'kubernetes.io/ingress.class': 'nginx',
    'nginx.ingress.kubernetes.io/proxy-body-size': '2400m',
    'nginx.ingress.kubernetes.io/proxy-connect-timeout': '600',
    'nginx.ingress.kubernetes.io/proxy-read-timeout': '600',
    'nginx.ingress.kubernetes.io/proxy-send-timeout': '600'
    },


    Has anyone faced this issue before?

    Continue reading...

Compartilhe esta Página