Skip to content

Commit 2ecb1bb

Browse files
Feat public url (#124)
Co-authored-by: Sudeep Pillai <sudeep.pillai@gmail.com>
1 parent 6e80f48 commit 2ecb1bb

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

vlmrun/client/files.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ def get_cached_file(self, file: Union[Path, str]) -> Optional[FileResponse]:
7575
if status_code == 200:
7676
file_response = FileResponse(**response)
7777
# Check if the file exists by checking if id is empty
78+
logger.debug(f"File response [file_response={file_response.id}]")
7879
if file_response.id:
80+
# Generate public URL if not already present
81+
if not file_response.public_url:
82+
file_response.public_url = self.get_public_url(file_response.id)
7983
return file_response
8084
else:
8185
return None
@@ -231,6 +235,29 @@ def get_content(self, file_id: str) -> bytes:
231235
"""
232236
raise NotImplementedError("Not implemented")
233237

238+
def get_public_url(self, file_id: str, expiration_minutes: int = 60) -> str:
239+
"""Get a public URL for a file.
240+
241+
Args:
242+
file_id: ID of file to get public URL for
243+
expiration_minutes: URL expiration time in minutes (default: 60)
244+
245+
Returns:
246+
str: Public URL for the file
247+
"""
248+
response, status_code, headers = self._requestor.request(
249+
method="GET",
250+
url=f"files/{file_id}/public-url",
251+
params={"expiration_minutes": expiration_minutes},
252+
)
253+
254+
if status_code == 200 and isinstance(response, dict):
255+
return response.get("public_url", "")
256+
else:
257+
# Fallback: construct a basic URL if the endpoint doesn't exist
258+
base_url = self._client.base_url.rstrip("/")
259+
return f"{base_url}/files/{file_id}/content"
260+
234261
def delete(self, file_id: str) -> FileResponse:
235262
"""Delete a file.
236263

vlmrun/client/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class FileResponse(BaseModel):
3535
]
3636
created_at: datetime
3737
object: str = "file"
38+
public_url: Optional[str] = None
3839

3940

4041
class PresignedUrlResponse(BaseModel):
@@ -218,6 +219,7 @@ def validate_config(self):
218219
raise ValueError(
219220
"`response_model` and `json_schema` cannot be used together, please provide only one."
220221
)
222+
return self
221223

222224
def model_dump(self, **kwargs) -> dict:
223225
"""Dump the config as a dictionary, converting response_model to json_schema if present."""

vlmrun/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.3.3"
1+
__version__ = "0.3.4"

0 commit comments

Comments
 (0)