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

Add a file using api #131

Closed
aniket-kumar opened this issue Jun 8, 2016 · 25 comments
Closed

Add a file using api #131

aniket-kumar opened this issue Jun 8, 2016 · 25 comments
Labels

Comments

@aniket-kumar
Copy link

aniket-kumar commented Jun 8, 2016

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?

@aniket-kumar
Copy link
Author

aniket-kumar commented Jun 9, 2016

@harshetha I am not able to see your comment. I think your response can help a lot to solve this issue. Thanks in advance

@harshetha
Copy link

harshetha commented Jun 9, 2016

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.
ipfs-inactive/examples#17
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
wrote:

@harshetha 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
#131 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AMCNTjkl5eGvRiYXXZ---PnLdGZZVNi4ks5qJ8DjgaJpZM4Iwrvg
.

@aniket-kumar
Copy link
Author

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.

@harshetha
Copy link

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
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
#131 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AMCNTiBfbahsbHIBAicGV557o_JDu40gks5qKB_OgaJpZM4Iwrvg
.

@aniket-kumar
Copy link
Author

aniket-kumar commented Jun 10, 2016

I just followed this :
https://www.npmjs.com/package/ipfs-js

let me know about any progress... :)

@harshetha
Copy link

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
wrote:

I just followed this :
https://www.npmjs.com/package/ipfs-js


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#131 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AMCNTqY3kMmZwHAMF-Y-fh1O5AVkehtmks5qKQDagaJpZM4Iwrvg
.

@harshetha
Copy link

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> 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
wrote:

I just followed this :
https://www.npmjs.com/package/ipfs-js


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#131 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AMCNTqY3kMmZwHAMF-Y-fh1O5AVkehtmks5qKQDagaJpZM4Iwrvg
.

@aniket-kumar
Copy link
Author

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.

@aniket-kumar
Copy link
Author

@harshetha any progress?

@harshetha
Copy link

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
wrote:

@harshetha https://github.com/harshetha any progress?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#131 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AMCNTo1h19ctf4cM2M8r1Y_sMQt3OUpnks5qLT_xgaJpZM4Iwrvg
.

@aniket-kumar
Copy link
Author

yeah, you are right. I was also thinking same.

@harshetha
Copy link

I am also trying out this
https://www.npmjs.com/package/ipfs-client#add---store-the-content-of-a-stream

On Mon, Jun 13, 2016 at 10:09 AM, aniket-kumar 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
#131 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AMCNTlfcknb3MnGaiDIzEGqM125iljH7ks5qLWSngaJpZM4Iwrvg
.

@aniket-kumar
Copy link
Author

ok, let me know about any progress...go ahead

@RichardLitt
Copy link
Contributor

@diasdavid Can you answer this?

@daviddias
Copy link

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

Try first using 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

@aniket-kumar
Copy link
Author

@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

@daviddias
Copy link

@aniket-kumar, try with ipfs.files.add

@aniket-kumar
Copy link
Author

aniket-kumar commented Jun 15, 2016

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

@aniket-kumar
Copy link
Author

@harshetha @RichardLitt @diasdavid any new findings?

@ttaveira
Copy link

ttaveira commented Jul 5, 2016

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?

@neuronsupport
Copy link

neuronsupport commented Nov 21, 2016

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.

@victorb
Copy link

victorb commented Nov 22, 2016

@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: https://github.com/ipfs/js-ipfs-api#callbacks-and-promises

@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 https://github.com/ipfs/interface-ipfs-core/ 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: https://github.com/VictorBjelkholm/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

@Kubuxu
Copy link

Kubuxu commented Nov 22, 2016

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

@Kubuxu Kubuxu reopened this Nov 22, 2016
@flyingzumwalt
Copy link
Contributor

This issue was moved to https://discuss.ipfs.io/t/add-a-file-using-api/278

@vurumadla
Copy link

hi can anyone give a solution to this..

GET /frontend/css/bootstrap.min.css.map 404 2.993 ms - -
req :Bg-Amendment-Chaincode.docx
ReferenceError: document is not defined
at Object.handle (D:\TF_23_8\TF_LATEST\appOriginal.js:274:15)
at next_layer (D:\TF_23_8\TF_LATEST\node_modules\express\lib\router\route.js:103:13)
at Route.dispatch (D:\TF_23_8\TF_LATEST\node_modules\express\lib\router\route.js:107:5)
at D:\TF_23_8\TF_LATEST\node_modules\express\lib\router\index.js:195:24
at param (D:\TF_23_8\TF_LATEST\node_modules\express\lib\router\index.js:268:14)
at param (D:\TF_23_8\TF_LATEST\node_modules\express\lib\router\index.js:280:16)
at Function.proto.process_params (D:\TF_23_8\TF_LATEST\node_modules\express\lib\router\index.js:296:3)
at next (D:\TF_23_8\TF_LATEST\node_modules\express\lib\router\index.js:189:19)
at Layer.staticMiddleware [as handle] (D:\TF_23_8\TF_LATEST\node_modules\express\node_modules\serve-static\index.js:55:61)
at trim_prefix (D:\TF_23_8\TF_LATEST\node_modules\express\lib\router\index.js:226:17)
POST /file-upload:Bg-Amendment-Chaincode.docx 500 119.852 ms - 937
POST /file-upload:Bg-Amendment-Chaincode.docx 500 121.013 ms - 937
[ibc-js] GetAllLC - failure: 408 Request timed out

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

10 participants