Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I add/retrieve a raw buffer to IPFS? #6

Open
VictorTaelin opened this issue May 2, 2018 · 5 comments
Open

How can I add/retrieve a raw buffer to IPFS? #6

VictorTaelin opened this issue May 2, 2018 · 5 comments

Comments

@VictorTaelin
Copy link

Just wondering if that usage is implemented. Thanks :)

@gkbrk
Copy link
Owner

gkbrk commented May 5, 2018

When you say add a raw buffer, do you mean adding it as a file or creating a block?

@VictorTaelin
Copy link
Author

I don't know what the best option would be. I just want to upload and retrieve raw data from a decentralized store. Suggestion?

@gkbrk
Copy link
Owner

gkbrk commented May 11, 2018

I added an API to add and retrieve blocks to the new version. Let me know if there are any problems with it.

TODO: Write docs for the block api

@VictorTaelin
Copy link
Author

Wow, well, thank you very much. Sadly, I didn't manage to use it. Am I doing something wrong? I've started IPFS with ipfs daemon. Then the following code:

let api = IpfsApi::new("127.0.0.1", 5001);
let hash = api.block_put("Hello world".as_bytes()).unwrap();
assert_eq!(hash, "QmV8cfu6n4NT5xRr2AHdKxFMTZEJrA44qgrBCr739BN9Wb");

Results in the following error:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: Json(Error("missing field `Key`", line: 1, column: 42)), url: None }', libcore/result.rs:945:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

If I replace the URL by "gateway.ipfs.io", I instead get:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: Json(Error("expected value", line: 1, column: 1)), url: None }', libcore/result.rs:945:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Changing it to "ipfs.io" or "gateway.ipfs.io" results in "Connection error". The other test also doesn't work for similar reasons. Chances are this is some misunderstanding of my part about how IPFS works, but I'm not sure what it is, given that I'm used the same code on your tests, so it should work. Perhaps I'm opening IPFS wrongly, and also using the gateways incorrectly?

@gkbrk
Copy link
Owner

gkbrk commented May 14, 2018

As you mentioned, that code is part of the tests. When I run the code on my machine, it passes successfully.

You can try to run IPFS from the command line with the ipfs block put and ipfs block get commands in order to see if your IPFS daemon is running correctly.

gateway.ipfs.io does not let you create blocks. It only allows you to download them. To connect to the public gateway, try connecting with IpfsApi::new("gateway.ipfs.io", 80);

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

No branches or pull requests

2 participants