def push_bytes_to_ipfs(bytes_in): """ Call the IPFS API to add the byte string to IPFS. When IPFS returns a hash, return this to the caller """ # Returns unicode in py2.7, str in py3.7 try: res = ipfs_client().add_bytes(bytes_in) # bytes) except TypeError as _: print('fail') log_error('IPFS_API had an issue pushing the item to IPFS') log_error(sys.exc_info()) log_error(len(bytes_in)) traceback.print_tb(sys.exc_info()[-1]) except ipfsapi.exceptions.ConnectionError as _: print('ConnErr') log_error(sys.exc_info()) traceback.print_tb(sys.exc_info()[-1]) return # TODO: verify that the add was successful if type(res).__name__ == 'unicode': return res elif type(res).__name__ == 'str': return res log_error('NEITHER UNICODE NOR STR RETURNED.') return res[0]['Hash']
def pull_from_ipfs(hash_in): return ipfs_client().cat(hash_in)