Skip to content

CID v1 retrieved from client.add is different with the CID retrieved from IPFS API or CLI #293

Open
@shc261392

Description

@shc261392

Problem

The CID v1 retrieved using the ipfshttpclient is different with the CID retrieved using IPFS HTTP API or CLI directly.

Environment

OS: Ubuntu 20.04
Python version: 3.8.5
Package version: ipfshttpclient==0.8.0a2
ipfs version: 0.8.0

Minimal code to reproduce the problem

Using an empty file to reproduce the problem. The problem is also reproducible using any file.

>>> import io
>>> import ipfshttpclient
>>> host_addr = '/dns4/localhost/tcp/5001/http'
>>> client = ipfshttpclient.connect(host_addr)

>>> file_object = io.BytesIO(b'')
>>> client.add(file_object, opts={'cid-version': 1})
<ipfshttpclient.client.base.ResponseBase: {'Name': 'bafybeif7ztnhq65lumvvtr4ekcwd2ifwgm3awq4zfr3srh462rwyinlb4y', 'Hash': 'bafybeif7ztnhq65lumvvtr4ekcwd2ifwgm3awq4zfr3srh462rwyinlb4y', 'Size': '6'}>
>>> import io
>>> import requests
>>> url = 'http://localhost:5001/api/v0/add'
>>> params = {'cid-version': 1}

>>> file_object = io.BytesIO(b'')
>>> requests.post(url, params=params, files={'file': file_object})
{'Name': 'file', 'Hash': 'bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku', 'Size': '0'}
$ touch empty
$ ipfs add --cid-version 1 empty
added bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku empty

As seen in the response, the response get from using ipfshttpclient has different CID from the one get using HTTP API or CLI. Also, the size should actually be 0, not 6.
If using a file with some content (not empty), the size difference could be observed as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions