Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Uploaded file via Spawned Node not accessible via public gateway #886

Closed
hhff opened this issue Jun 29, 2017 · 10 comments
Closed

Uploaded file via Spawned Node not accessible via public gateway #886

hhff opened this issue Jun 29, 2017 · 10 comments
Labels
kind/support A question or request for support

Comments

@hhff
Copy link

hhff commented Jun 29, 2017

I'm building a deploy step for a simple JS app. My understanding of the steps required to propogate something to IPFS via the JS wrapper is:

1. Build App (via Webpack etc)
2. Create buffers / readable streams for built files
3. Spawn IPFS node via `let node = new IPFS()`
4. Upload files via `node.files.add`

Write now, the code is as follows:

let node;
return new RSVP.Promise(function(resolve, reject) {
  node = new IPFS();
  node.on('ready', () => {
    // file here will eventually comprise a built web app
    let file = new node.types.Buffer('/hello.txt');
    node.files.add([{
      path: '/hello.txt',
      content: file
    }], function(err, files) {
      if (err) { return reject(err); }
      return resolve(files);
    });
  });
}).finally(() => {
  if (node) node.stop();
});

This resolves a hash successfully without throwing err. However, when I navigate to
https://gateway.ipfs.io/ipfs/${files[0].hash}, the file doesn't actually resolve.

What am I missing here?

I'm guessing that while the file has uploaded to the local node, it gets stopped before the file has propagated to a permanent node on the network. If that's correct, how do I know how to keep the local node alive long enough for it to propagate to the gateway?

@victorb
Copy link
Member

victorb commented Jun 30, 2017 via email

@hhff
Copy link
Author

hhff commented Jun 30, 2017

Thanks @victorbjelkholm - makes sense!

I'll add a step that fetches the file from the public gateway (probably just via a HEAD request) after I receive the hash, and keep the node alive until that's successful.

Does that seem like a sane approach?

Also, if I uploaded a directory, would I need to make that HEAD request for each file, or is it fine to just make it once for the hash that corresponds to the root directory?

@victorb
Copy link
Member

victorb commented Jun 30, 2017 via email

@hhff
Copy link
Author

hhff commented Jun 30, 2017

Ah! Thankyou.

How do I go about pinning content via JS? I want to be sure the deploy is permanent.

I'm also running a node on a VPS (digital ocean) - but haven't made it accessible to the outside world yet.

(Going to write an article about this so will link back here to help others understand!)

@hhff
Copy link
Author

hhff commented Jul 1, 2017

Success! Thanks @victorbjelkhom ! Built app is available here: www.ember-cli-deploy-ipfs.com (although IPNS seems very slow).

Am I right in thinking that running:
ipfs name publish ${rootHash}

Is the same as "pinning"? Or is that a different concept?

@daviddias
Copy link
Member

Hi @hhff! great to see that this got figured out, thanks @victorbjelkholm for jumping in :)

ipfs name is for IPNS names, our distributed naming system that gives you mutable pointers in the network. What you are looking is for ipfs pin.

We have a WIP PR for the pinning API in js #107, it is missing the update to use the new IPFS Repo datastore and more tests. If you wanna help on that, it will be hugely appreciated :)

@daviddias daviddias added kind/support A question or request for support status/deferred Conscious decision to pause or backlog labels Jul 3, 2017
@hhff
Copy link
Author

hhff commented Jul 5, 2017

Thanks @diasdavid - I'll take a look at the pinning PR and see if I can lend a hand.

Naming is another important part of the deploy step (that's how we'll do the activation of the new deploy) - are there any plans to supporting ipfs name in the JS lib?

@victorb
Copy link
Member

victorb commented Jul 5, 2017

@hhff currently, we have this issue to track the work on IPNS: #209

But I think that issue needs an update. Last time I've spoken with @diasdavid and @dignifiedquire we're planning to start working on IPNS once dht is ready and done for js-ipfs, dht work is being tracked here: #856

Edit: just updated the issue

@daviddias
Copy link
Member

Closing this issue, track IPNS at #209 :)

@daviddias daviddias removed the status/deferred Conscious decision to pause or backlog label Jul 7, 2017
@hhff
Copy link
Author

hhff commented Jul 7, 2017 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/support A question or request for support
Projects
None yet
Development

No branches or pull requests

3 participants