From cf83952a1906f4831bf7623ba98172a8d3a85667 Mon Sep 17 00:00:00 2001 From: gilesb Date: Tue, 13 Jan 2026 04:44:11 +0000 Subject: [PATCH] Fix add_file to accept both Path and string --- ipfs_client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ipfs_client.py b/ipfs_client.py index 85cba7c..8d71758 100644 --- a/ipfs_client.py +++ b/ipfs_client.py @@ -45,18 +45,22 @@ def _multiaddr_to_url(multiaddr: str) -> str: IPFS_BASE_URL = _multiaddr_to_url(IPFS_API) -def add_file(file_path: Path, pin: bool = True) -> Optional[str]: +def add_file(file_path: Union[Path, str], pin: bool = True) -> Optional[str]: """ Add a file to IPFS and optionally pin it. Args: - file_path: Path to the file to add + file_path: Path to the file to add (Path object or string) pin: Whether to pin the file (default: True) Returns: IPFS CID (content identifier) or None on failure """ try: + # Ensure file_path is a Path object + if isinstance(file_path, str): + file_path = Path(file_path) + url = f"{IPFS_BASE_URL}/api/v0/add" params = {"pin": str(pin).lower()}