@@ -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
0 commit comments