# Add a file using api

**URL:** <https://discuss.ipfs.tech/t/add-a-file-using-api/278>\
**Category:** Help\
**Created:** [May 23, 2017, 12:06am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278 "2017-05-23T00:06:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:06am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/1 "2017-05-23T00:06:55Z")

</div>

_From @aniket-kumar on Wed Jun 08 2016 07:46:21 GMT+0000 (UTC)_  
  
I want to create a webpage in which user will upload a file and that file will be uploaded on ipfs and i will get the hash of file internally. I think i can do this using the apis of ipfs but i didn’t get any particular documentation of ipfs apis. Tell me, How can i solve this purpose?  
  
  
_Copied from original issue: [Add a file using api · Issue #131 · ipfs-inactive/faq · GitHub](https://github.com/ipfs/faq/issues/131)_

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:07am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/2 "2017-05-23T00:07:50Z")

</div>

_From @aniket-kumar on Thu Jun 09 2016 07:29:37 GMT+0000 (UTC)_  
  
@Harshetha I am not able to see your comment. I think your response can help a lot to solve this issue. Thanks in advance

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:08am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/3 "2017-05-23T00:08:15Z")

</div>

_From @harshetha on Thu Jun 09 2016 13:48:53 GMT+0000 (UTC)_  
  
I am working on a web scenario where I have to upload a file into ipfs and  
then retrieve the document hash. I am working off of this code I have  
linked but it is not fully functional, just a general idea of how to call  
functions from the ipfs api using Node.js.

> <https://github.com/ipfs-inactive/examples/issues/17>
>
> Note to self. Something like:
> 
> Write this to index.js
> 
> \`\`\` javascript
> var ipfs …= require('ipfs-api')();
> 
> function store() {
> var toStore = document.getElementById('source').value;
> //TODO un-break this call:
> ipfs.add(new Buffer(toStore), function (err, res){
> if(err || !res) return console.error("ipfs add error", err, res);
> 
> res.forEach(function(file) {
> console.log('successfully stored', file.Hash);
> display(file.Hash); 
> });
> });
> }
> 
> function display(hash) {
> ipfs.cat(hash, function(err, res) {
> if(err || !res) return console.error("ipfs cat error", err, res);
> if(res.readable) {
> console.error('unhandled: cat result is a pipe', res);
> } else {
> document.getElementById('hash').innerText=hash;
> document.getElementById('content').innerText=res;
> }
> });
> }
> 
> document.getElementById('store').onclick=store;
> \`\`\`
> 
> \`\`\` bash
> \#sloppy html demo
> echo '\<textarea id="source"\>\</textarea\>
> \<button id="store"\>create in ipfs\</button\>
> \<div\>\<div\>found in ipfs:\</div\>
> \<div id="hash"\>\[ipfs hash\]\</div\>
> \<div id="content"\>\[ipfs content\]\</div\>\</div\>
> \<script type="text/javascript" src="ipfs.js"\>\</script\>' \> index.html
> 
> \#file server
> sudo npm install -g browserify http-server
> npm install ipfs-api
> browserify index.js \> ipfs.js #do this every time you change index.js, or better: set up grunt watch
> http-server -a 127.0.0.1 -p 8888
> 
> \#ipfs server
> export API\_ORIGIN="http://localhost:8888"
> ipfs daemon
> \`\`\`
> 
> Open \[http://localhost:8888/index.html\](http://localhost:8888/index.html)

Let me know if you find something further and I will do the same

On Thu, Jun 9, 2016 at 3:29 AM, aniket-kumar [notifications@github.com](mailto:notifications@github.com)  
wrote:

> @Harshetha [harshetha (Harshetha Sundar) · GitHub](https://github.com/Harshetha) I am not able to see your  
> comment. I think your help can help a lot to solve this issue. Thanks in  
> advance
> 
> —  
> You are receiving this because you were mentioned.  
> Reply to this email directly, view it on GitHub  
> [Add a file using api · Issue #131 · ipfs-inactive/faq · GitHub](https://github.com/ipfs/faq/issues/131#issuecomment-224819993), or mute  
> the thread  
> [GitHub · Where software is built](https://github.com/notifications/unsubscribe/AMCNTjkl5eGvRiYXXZ---PnLdGZZVNi4ks5qJ8DjgaJpZM4Iwrvg)  
> .

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:08am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/4 "2017-05-23T00:08:37Z")

</div>

_From @aniket-kumar on Thu Jun 09 2016 14:14:30 GMT+0000 (UTC)_  
  
I have tried multiple approaches found from anywhere but none of them is working to upload a file. Yeah, i come to learn how to upload text only. I don’t know if any api of ipfs is made for this purpose.

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:08am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/5 "2017-05-23T00:08:49Z")

</div>

_From @harshetha on Thu Jun 09 2016 19:20:04 GMT+0000 (UTC)_  
  
Can I see how you uploaded text? Maybe I can add some commands and combine  
my knowledge to figure out how to upload a file.

On Thu, Jun 9, 2016 at 10:14 AM, aniket-kumar [notifications@github.com](mailto:notifications@github.com)  
wrote:

> I have tried multiple approaches found from anywhere but none of them is  
> working to upload a file. Yeah, i come to learn how to upload text only. I  
> don’t know if any api of ipfs is made for this purpose.
> 
> —  
> You are receiving this because you were mentioned.  
> Reply to this email directly, view it on GitHub  
> [Add a file using api · Issue #131 · ipfs-inactive/faq · GitHub](https://github.com/ipfs/faq/issues/131#issuecomment-224907566), or mute  
> the thread  
> [GitHub · Where software is built](https://github.com/notifications/unsubscribe/AMCNTiBfbahsbHIBAicGV557o_JDu40gks5qKB_OgaJpZM4Iwrvg)  
> .

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:08am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/6 "2017-05-23T00:08:57Z")

</div>

_From @aniket-kumar on Fri Jun 10 2016 06:14:48 GMT+0000 (UTC)_  
  
I just followed this :

> **[ipfs-js](https://www.npmjs.com/package/ipfs-js)**
>
> Helper methods for ipfs-api

let me know about any progress… 🙂

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:09am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/7 "2017-05-23T00:09:05Z")

</div>

_From @harshetha on Fri Jun 10 2016 13:55:04 GMT+0000 (UTC)_  
  
I have tried this before but it did not work for me, can I see your code  
and file structure?

Thanks  
Harshetha

On Fri, Jun 10, 2016 at 2:14 AM, aniket-kumar [notifications@github.com](mailto:notifications@github.com)  
wrote:

> I just followed this :  
> [ipfs-js - npm](https://www.npmjs.com/package/ipfs-js)
> 
> —  
> You are receiving this because you were mentioned.  
> Reply to this email directly, view it on GitHub  
> [Add a file using api · Issue #131 · ipfs-inactive/faq · GitHub](https://github.com/ipfs/faq/issues/131#issuecomment-225102066), or mute  
> the thread  
> [GitHub · Where software is built](https://github.com/notifications/unsubscribe/AMCNTqY3kMmZwHAMF-Y-fh1O5AVkehtmks5qKQDagaJpZM4Iwrvg)  
> .

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:09am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/8 "2017-05-23T00:09:10Z")

</div>

_From @harshetha on Fri Jun 10 2016 14:03:24 GMT+0000 (UTC)_  
  
I also think I know how to integrate the file upload with ipfs but having a  
few issues

On Fri, Jun 10, 2016 at 9:55 AM, Harshetha Sundar \<  
[harshetha.sundar@gmail.com](mailto:harshetha.sundar@gmail.com)\> wrote:

> I have tried this before but it did not work for me, can I see your code  
> and file structure?
> 
> Thanks  
> Harshetha
> 
> On Fri, Jun 10, 2016 at 2:14 AM, aniket-kumar [notifications@github.com](mailto:notifications@github.com)  
> wrote:
> 
> > I just followed this :  
> > [ipfs-js - npm](https://www.npmjs.com/package/ipfs-js)
> > 
> > —  
> > You are receiving this because you were mentioned.  
> > Reply to this email directly, view it on GitHub  
> > [Add a file using api · Issue #131 · ipfs-inactive/faq · GitHub](https://github.com/ipfs/faq/issues/131#issuecomment-225102066), or mute  
> > the thread  
> > [GitHub · Where software is built](https://github.com/notifications/unsubscribe/AMCNTqY3kMmZwHAMF-Y-fh1O5AVkehtmks5qKQDagaJpZM4Iwrvg)  
> > .

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:09am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/9 "2017-05-23T00:09:14Z")

</div>

_From @aniket-kumar on Fri Jun 10 2016 14:11:53 GMT+0000 (UTC)_  
  
It was also not working on my system but when i uploaded it to ipfs and executed it from ipfs then it worked for me. Try that. Follow all the steps given in that link till 4th one.

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:09am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/10 "2017-05-23T00:09:17Z")

</div>

_From @aniket-kumar on Mon Jun 13 2016 11:33:03 GMT+0000 (UTC)_  
  
@harshetha any progress?

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:09am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/11 "2017-05-23T00:09:20Z")

</div>

_From @harshetha on Mon Jun 13 2016 14:08:34 GMT+0000 (UTC)_  
  
No, the issue is that the files.add function is not yet implemented in the  
index.js or the load-commands.js (these files are called in the ipfs api),  
we either need to write our own function or find someone’s fork that  
already has it.

On Mon, Jun 13, 2016 at 7:33 AM, aniket-kumar [notifications@github.com](mailto:notifications@github.com)  
wrote:

> @harshetha [harshetha (Harshetha Sundar) · GitHub](https://github.com/harshetha) any progress?
> 
> —  
> You are receiving this because you were mentioned.  
> Reply to this email directly, view it on GitHub  
> [Add a file using api · Issue #131 · ipfs-inactive/faq · GitHub](https://github.com/ipfs/faq/issues/131#issuecomment-225556349), or mute  
> the thread  
> [GitHub · Where software is built](https://github.com/notifications/unsubscribe/AMCNTo1h19ctf4cM2M8r1Y_sMQt3OUpnks5qLT_xgaJpZM4Iwrvg)  
> .

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:09am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/12 "2017-05-23T00:09:23Z")

</div>

_From @aniket-kumar on Mon Jun 13 2016 14:09:41 GMT+0000 (UTC)_  
  
yeah, you are right. I was also thinking same.

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:09am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/13 "2017-05-23T00:09:25Z")

</div>

_From @harshetha on Mon Jun 13 2016 15:06:52 GMT+0000 (UTC)_  
  
I am also trying out this

> **[ipfs-client](https://www.npmjs.com/package/ipfs-client#add---store-the-content-of-a-stream)**
>
> A client library to talk to local IPFS daemons. Latest version: 0.10.1, last published: 6 months ago. Start using ipfs-client in your project by running \`npm i ipfs-client\`. There are 6 other projects in the npm registry using ipfs-client.

On Mon, Jun 13, 2016 at 10:09 AM, aniket-kumar [notifications@github.com](mailto:notifications@github.com)  
wrote:

> yeah, you are right. I was also thinking same.
> 
> —  
> You are receiving this because you were mentioned.  
> Reply to this email directly, view it on GitHub  
> [Add a file using api · Issue #131 · ipfs-inactive/faq · GitHub](https://github.com/ipfs/faq/issues/131#issuecomment-225591951), or mute  
> the thread  
> [GitHub · Where software is built](https://github.com/notifications/unsubscribe/AMCNTlfcknb3MnGaiDIzEGqM125iljH7ks5qLWSngaJpZM4Iwrvg)  
> .

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:09am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/14 "2017-05-23T00:09:26Z")

</div>

_From @aniket-kumar on Tue Jun 14 2016 11:30:07 GMT+0000 (UTC)_  
  
ok, let me know about any progress…go ahead

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:09am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/15 "2017-05-23T00:09:28Z")

</div>

_From @RichardLitt on Tue Jun 14 2016 11:33:49 GMT+0000 (UTC)_  
  
@diasdavid Can you answer this?

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:09am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/16 "2017-05-23T00:09:28Z")

</div>

_From @diasdavid on Tue Jun 14 2016 21:59:51 GMT+0000 (UTC)_  
  
You can upload a file to IPFS using the `js-ipfs-api`(HTTP Client Library, works with Go or JS IPFS nodes) or `js-ipfs` (Full node in JS) using the interface defined here [https://github.com/ipfs/interface-ipfs-core#files](https://github.com/ipfs/interface-ipfs-core#files)

Try first using [https://github.com/ipfs/js-ipfs-api](https://github.com/ipfs/js-ipfs-api) and the go-ipfs daemon and let me know of your results. Note that you will have to set the CORS headers this way [https://github.com/ipfs/js-ipfs-api#cors](https://github.com/ipfs/js-ipfs-api#cors)

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:09am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/17 "2017-05-23T00:09:29Z")

</div>

_From @aniket-kumar on Wed Jun 15 2016 05:36:16 GMT+0000 (UTC)_  
  
@diasdavid i tried this js-ipfs-api. It is working fine for ipfs.id but when i tried to use **ipfs.add(“string”).then(callback)** , it showed the error : _Uncaught TypeError: ipfs.add is not a function_

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:09am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/18 "2017-05-23T00:09:30Z")

</div>

_From @diasdavid on Wed Jun 15 2016 06:04:43 GMT+0000 (UTC)_  
  
@aniket-kumar, try with `ipfs.files.add`

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:09am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/19 "2017-05-23T00:09:31Z")

</div>

_From @aniket-kumar on Wed Jun 15 2016 06:16:17 GMT+0000 (UTC)_  
  
@diasdavid now new error : `Uncaught TypeError: cb is not a function` in add.js  
I am trying to add the string as _ipfs.files.add(“hey”)_ . I also tried it with hex and binary format of string. It is giving the same error.

---

<div class="post-metadata">

**Author:** ![flyingzumwalt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/flyingzumwalt/32/12_2.png) [@flyingzumwalt](https://discuss.ipfs.tech/u/flyingzumwalt)\
**Post date:** [May 23, 2017, 12:09am UTC](https://discuss.ipfs.tech/t/add-a-file-using-api/278/20 "2017-05-23T00:09:32Z")

</div>

_From @aniket-kumar on Thu Jun 23 2016 05:22:49 GMT+0000 (UTC)_  
  
@harshetha @RichardLitt @diasdavid any new findings?

[Next page](https://discuss.ipfs.tech/t/add-a-file-using-api/278.md?page=2)
