ipfs-shipyard / ipfs-shipyard/py-ipfs-http-client

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

Open
#293 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
685
Forks
200
PR merge metrics
No merged PRs in 30d

Description

## 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.

```python3
>>> 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})

```

```python3
>>> 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'}
```

```bash
$ 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.