How to use the ipfshttpclient.multipart function in ipfshttpclient

To help you get started, we’ve selected a few ipfshttpclient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ipfs / py-ipfs-http-client / test / unit / test_multipart.py View on Github external
test/functional/fake_dir
		Changing that directory or its contents could break the test.
		"""
		# Get OS-agnostic path to test files
		path = os.path.join(os.path.dirname(os.path.dirname(__file__)),
		                    "functional", "fake_dir")
		# Collect absolute paths to all test files
		filenames_list = []
		for (dirpath, _, filenames) in os.walk(path):
			temp_list = [os.path.join(dirpath, name) for name in filenames]
			filenames_list.extend(temp_list)
		# Convert absolute paths to relative
		relative_paths_list = [os.path.relpath(cur_path, os.getcwd())
		                       for cur_path in filenames_list]

		instance = ipfshttpclient.multipart.FilesStream(relative_paths_list)

		expected = "(--\S+\r\nContent-Disposition: file; filename=\"\S+\""\
			+ "\r\nContent-Type: application/\S+\r\n"\
			+ "\r\n(.|\n)*\r\n)+--\S+--\r\n"
		actual = ""
		for i in instance.body():
			if type(i) is not str and type(i) is not memoryview:
				i = i.decode()
			elif six.PY3 and type(i) is memoryview:
				i = i.tobytes().decode()
			actual += i
		assert re.search(expected, actual)
github ipfs / py-ipfs-http-client / test / unit / test_multipart.py View on Github external
def test_body(self):
		"""Check the multipart HTTP body for the streamed directory."""
		# Get OS-agnostic path to test files
		text = b"Here is some text for this test."
		instance = ipfshttpclient.multipart.BytesFileStream(text)
		expected = b"(--\S+\r\nContent-Disposition: file; filename=\"\S+\""\
			+ b"\r\nContent-Type: application/\S+\r\n"\
			+ b"\r\n(.|\n)*\r\n)+--\S+--\r\n"
		actual = b"".join(instance.body())
		assert re.search(expected, actual)
github ipfs / py-ipfs-http-client / ipfshttpclient / client.py View on Github external
>>> c.add_str(u"Mary had a little lamb")
            'QmZfF6C9j4VtoCsTp4KSrhYH47QMd3DNXVZBKaxJdhaPab'

        Also accepts and will stream generator objects.

        Parameters
        ----------
        string : str
            Content to be added as a file

        Returns
        -------
            str : Hash of the added IPFS object
        """
        body, headers = multipart.stream_text(string, self.chunk_size)
        return self._client.request('/add', decoder='json',
                                    data=body, headers=headers, **kwargs)
github ipfs / py-ipfs-http-client / ipfshttpclient / client.py View on Github external
def connect(host=DEFAULT_HOST, port=DEFAULT_PORT, base=DEFAULT_BASE,
            chunk_size=multipart.default_chunk_size, **defaults):
    """Create a new :class:`~ipfshttpclient.Client` instance and connect to the
    daemon to validate that its version is supported.

    Raises
    ------
    ~ipfshttpclient.exceptions.VersionMismatch
    ~ipfshttpclient.exceptions.ErrorResponse
    ~ipfshttpclient.exceptions.ConnectionError
    ~ipfshttpclient.exceptions.ProtocolError
    ~ipfshttpclient.exceptions.StatusError
    ~ipfshttpclient.exceptions.TimeoutError


    All parameters are identical to those passed to the constructor of the
    :class:`~ipfshttpclient.Client` class.
github ipfs / py-ipfs-http-client / ipfshttpclient / client / base.py View on Github external
def __init__(self, addr=DEFAULT_ADDR, base=DEFAULT_BASE,
	             chunk_size=multipart.default_chunk_size,
	             session=False, **defaults):
		"""Connects to the API port of an IPFS node."""

		self.chunk_size = chunk_size

		self._client = self._clientfactory(addr, base, **defaults)
		if session:
			self._client.open_session()