Skip to content

Commit

Permalink
Merge pull request #76 from Multi-Agent-io/development
Browse files Browse the repository at this point in the history
1.3.4 return ipfs file size
  • Loading branch information
PaTara43 authored Sep 29, 2022
2 parents 7b70fb5 + b62dd0b commit 0439636
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,17 @@ 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_)
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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <p040399@outlook.com>"]
license = "Apache-2.0"
Expand Down
7 changes: 4 additions & 3 deletions robonomicsinterface/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
"""

Expand All @@ -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:
Expand Down

0 comments on commit 0439636

Please sign in to comment.