Add a file using api

From @ttaveira on Tue Jul 05 2016 15:27:28 GMT+0000 (UTC)

I’m trying to do the same thing. If I understand correctly, ipfs.files.add requires a Bufferor Readable Stream (Node.js types). Are we able to use the js-ipfs-api without Node?

Also, is there any difference between ipfs.files.add and ipfs.add?

From @norzak on Mon Nov 21 2016 15:22:51 GMT+0000 (UTC)

ipfs-js is node.js only I guess. If we could not write/move/copy/delete files from web browser in a way, how would ipfs be useful to anyone other than showing static web pages.

From @VictorBjelkholm on Tue Nov 22 2016 12:01:11 GMT+0000 (UTC)

@aniket-kumar

You have two different ways of using the ipfs.files.add method. Either you define a callback like this:

ipfs.files.add([new Buffer('hello world')], (err, res) => {
// do something with res
})

Or use it with promises:

ipfs.files.add([new Buffer('hello world')]).then((res) => {
// do something with res
}).catch((err) => { /* handle err */ })

It’s mentioned in the readme over here: GitHub - ipfs-inactive/js-ipfs-http-client: [ARCHIVED] now part of the https://github.com/ipfs/js-ipfs repo

@ttaveira

Are we able to use the js-ipfs-api without Node?

Yes, it works in the browser as well. You have some examples here: https://github.com/ipfs/js-ipfs-api/tree/master/examples

Also, is there any difference between ipfs.files.add and ipfs.add?

No, it’s merely there to fulfill the interface we defined in GitHub - ipfs-inactive/interface-js-ipfs-core: [ARCHIVED] now part of the https://github.com/ipfs/js-ipfs repo while remaining backwards compatibility.

@norzak No, js-ipfs works in the browser as well. There are examples in the repository itself (here: https://github.com/ipfs/js-ipfs/tree/master/examples) and I’ve also made an example for passing around data you can check out here: GitHub - victorb/js-ipfs-passing-data

I’m gonna close this issue, and refer to future readers to open up issues in the appropriate repository if you’re having any troubles with either js-ipfs or js-ipfs-api

From @Kubuxu on Tue Nov 22 2016 13:31:48 GMT+0000 (UTC)

We are leaving issues open in FAQ repo so they are more easily visible.