You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FastAPI上传大文件时出现超时错误,求解决方案

FastAPI文件上传超时问题(返回200但上传中断)

我搭建了一个FastAPI端点,功能是接收tar格式的文件,保存到本地后用podman解压加载镜像,再推送到Artifactory地址。但现在不管是大文件,还是偶尔的小文件,上传过程中都会出现超时现象,而且接口还会返回200响应。我已经尝试调整了Nginx的相关配置,但问题依然没有解决。

FastAPI端点代码

@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,
        },
    }

Nginx Ingress注解配置

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'
}

有没有哪位开发者遇到过这类问题?

内容的提问来源于stack exchange,提问作者Tamilarasan Janakiraman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 13:37:27