ipfs.files.add: Notes about ipfs.types.Buffer.#373
ipfs.files.add: Notes about ipfs.types.Buffer.#373alanshaw merged 2 commits intoipfs-inactive:masterfrom
Conversation
I've spent an hour trying to figure out how to do `ipfs add` in the browser: docs describe the "Buffer" part really vaguely and don't mention that `ipfs.files.add` in fact creates a directory object unless used with a correctly created buffer. It works with an incorrectly created buffer, but creates a directory with auto-generated name:
```js
let data = new Uint8Array([0x41, 0x42, 0x43]);
let results = await ipfs.files.add(data);
```
Here `results` is
```json
[
{
"path": "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn",
"hash": "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn",
"size": 4
}
]
```
Now open this hash in `ipfs.io` and try to figure out wtf that is and why size is 4. The `ipfs.types.Buffer` was the key.
|
Thanks for the PR @klueq - lets get these docs fixed up so they're easier to understand. There's a few things going on here that I should mention: Firstly, js-ipfs doesn't seem to be validating the input correctly, you shouldn't be able to pass a When you pass it a Lastly, if you add some content like this: const files = [
{
path: '/tmp/myfile.txt',
content: ipfs.types.Buffer.from('ABC')
}
]You'll get a directory AND a file because you've specified the path as So you can now access |
SPEC/FILES.md
Outdated
| Now [ipfs.io/ipfs/Qm...WW](https://ipfs.io/ipfs/QmNz1UBzpdd4HfZ3qir3aPiRdX5a93XwTuDNyXRc6PKhWW) | ||
| returns the "ABC" string. | ||
|
|
||
| The following code creates a directory object: |
There was a problem hiding this comment.
I think we just need to tweak this wording to something like: "The following allows you to add multiple files at once. Note that intermediate directories in file paths will be automatically created and returned in the response along with files:"
I've spent an hour trying to figure out how to do
ipfs addin the browser: docs describe the "Buffer" part really vaguely and don't mention thatipfs.files.addin fact creates a directory object unless used with a correctly created buffer. It works with an incorrectly created buffer, but creates a directory with auto-generated name:Here
resultsis[ { "path": "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn", "hash": "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn", "size": 4 } ]Now open this hash in
ipfs.ioand try to figure out wtf that is and why size is 4. Theipfs.types.Bufferwas the key.