diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 819e97a..019b887 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -439,8 +439,8 @@ thing needed - account seed to sign an authentication message. seed = "seed" content = "Hello, World!" - cid = ipfs_upload_content(tester_tokens_seed, content) - print(cid) + cid, size = ipfs_upload_content(tester_tokens_seed, content) + print(cid, size) content_ = ipfs_get_content(cid) print(content_) @@ -448,8 +448,8 @@ thing needed - account seed to sign an authentication message. with open("path_to_file", 'rb') as f: content = f.read() - cid = ipfs_upload_content(tester_tokens_seed, content) - print(cid) + cid, size = ipfs_upload_content(tester_tokens_seed, content) + print(cid, size) content_ = ipfs_get_content(cid) with open("path_to_the_fetched_file", 'wb') as f: diff --git a/pyproject.toml b/pyproject.toml index de3367c..0cabdee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "robonomics-interface" -version = "1.3.3" +version = "1.3.4" description = "Robonomics wrapper over https://github.com/polkascan/py-substrate-interface created to facilitate programming with Robonomics" authors = ["Pavel Tarasov "] license = "Apache-2.0" diff --git a/robonomicsinterface/utils.py b/robonomicsinterface/utils.py index 2a18bdf..dfc3414 100644 --- a/robonomicsinterface/utils.py +++ b/robonomicsinterface/utils.py @@ -89,7 +89,7 @@ def str_to_scalebytes(data: tp.Union[int, str], type_str: str) -> ScaleBytes: return scale_obj.encode(data) -def ipfs_upload_content(seed: str, content: tp.Any, pin: bool = False) -> str: +def ipfs_upload_content(seed: str, content: tp.Any, pin: bool = False) -> tp.Tuple[str, int]: """ Upload content to IPFS and pin the CID for some time via IPFS Web3 Gateway with private-key-signed message. The signed message is user's pubkey. https://wiki.crust.network/docs/en/buildIPFSWeb3AuthGW#usage. @@ -98,7 +98,7 @@ def ipfs_upload_content(seed: str, content: tp.Any, pin: bool = False) -> str: :param content: Content to upload to IPFS. To upload media use open(.., "rb") and read(). :param pin: Whether pin file or not. - :return: IPFS cid. + :return: IPFS cid and file size. """ @@ -113,13 +113,14 @@ def ipfs_upload_content(seed: str, content: tp.Any, pin: bool = False) -> str: if response.status_code == 200: resp = literal_eval(response.content.decode("utf-8")) cid = resp["Hash"] + size = resp["Size"] else: raise FailedToUploadFile(response.status_code) if pin: _pin_ipfs_cid(keypair, cid) - return cid + return cid, size def _pin_ipfs_cid(keypair: Keypair, ipfs_cid: str) -> bool: