Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Error passing a filepath string to files.add #722

Closed
olizilla opened this issue Mar 23, 2018 · 2 comments
Closed

Error passing a filepath string to files.add #722

olizilla opened this issue Mar 23, 2018 · 2 comments

Comments

@olizilla
Copy link
Contributor

olizilla commented Mar 23, 2018

The interface spec suggests that from node you can call ipfs.add with a Path.
https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#add

ipfs.files.add(data, [options], [callback])
Where data may be:
a Buffer instance
a Readable Stream
a Pull Stream
a Path (caveat: will only work in Node.js)
a URL
an array of objects

Trying to pass a file system path as a string throws an error

Error: first arg must be a buffer, readable stream, an object or array of objects
    at Function.promisify (/Users/oli/Code/ipfs/js-ipfs-api/src/files/add.js:34:23)
    at Object.add (/Users/oli/Code/ipfs/js-ipfs-api/node_modules/promisify-es6/index.js:32:27)
    at Object.<anonymous> (/Users/oli/Code/ipfs/js-ipfs-api/examples/files-api/files-api.js:19:12)

Do I need to update the spec, or fix the implementation?

@victorb
Copy link
Contributor

victorb commented Mar 23, 2018

According to the tests, adding by path should fail: https://github.com/ipfs/interface-ipfs-core/blob/b862a12bc655954143b995887983f96201abcf31/js/src/files.js#L144-L151

I think the docs are wrong here, it was a long time ago that function accepted just a path. @diasdavid can you confirm that's the right behaviour?

olizilla added a commit to ipfs-inactive/interface-js-ipfs-core that referenced this issue Mar 23, 2018
@ghost ghost assigned olizilla Mar 23, 2018
@ghost ghost added the in progress label Mar 23, 2018
@daviddias
Copy link
Contributor

The plan was to merge add, addFromUrl and addFromFs into just add with -- ipfs-inactive/interface-js-ipfs-core#162 (comment) -- endeavor, that last bit was postponed and didn't get done.

What this means is that, yes the docs are wrong for the current implementation but what we would like is to improve the implementation to actually support it. Thanks @olizilla for catching this one :)

daviddias pushed a commit to ipfs-inactive/interface-js-ipfs-core that referenced this issue Mar 26, 2018
* You can't ipfs.add a path

Fixes ipfs-inactive/js-ipfs-http-client#722

* Remove URL from files.add
@ghost ghost removed the in progress label Mar 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants