Skip to content

Commit b56d846

Browse files
Bugfix in file_id arg parsing
1 parent 50c2df5 commit b56d846

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

routers/files.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import logging
33
from dotenv import load_dotenv
4-
from fastapi import APIRouter, Request, UploadFile, File, HTTPException, Depends, Form
4+
from fastapi import APIRouter, Request, UploadFile, File, HTTPException, Depends, Form, Path
55
from fastapi.responses import StreamingResponse
66
from openai import AsyncOpenAI
77

@@ -75,15 +75,18 @@ async def upload_file(file: UploadFile = File(...)):
7575

7676

7777
@router.get("/{file_id}")
78-
async def get_file(file_id: str = Form(...), client: AsyncOpenAI = Depends(lambda: AsyncOpenAI())):
78+
async def get_file(
79+
file_id: str = Path(..., description="The ID of the file to retrieve"),
80+
client: AsyncOpenAI = Depends(lambda: AsyncOpenAI())
81+
):
7982
try:
8083
# Retrieve file metadata and content concurrently
8184
file, file_content = await client.files.retrieve(file_id), await client.files.content(file_id)
8285

8386
# Return the file content as a streaming response
8487
return StreamingResponse(
8588
file_content.body,
86-
headers={"Content-Disposition": f'attachment; filename="{file.filename}"'}
89+
headers={"Content-Disposition": f'attachment; filename=\"{file.filename}\"'}
8790
)
8891
except Exception as e:
8992
# Handle exceptions and return an HTTP error response

0 commit comments

Comments
 (0)