Is there a way I can connect the API directly to my node. My app is deployed on my own node and I would like to be able to upload files from my app to my peer.
Most example use it like this;
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });
Is there a way I can connect to my node using the peer id? instead of an IP since I’m on a dynamic IP.
The app itself is hosted on my ipfs node. Is it really hard to have my app save a file to the node it’s hosted on?
Yes. You change the host to localhost
and the protocol to http
.
1 Like
So localhost will be used from the point of vue of my app being on the ipfs node and not the client own computer that is running the app.
No, it’ll be “localhost” on the client’s computer (they’ll need to run IPFS locally). If you want the end-user to use your IPFS node (the one running on your machine), you need to expose it to the internet and give it a static address. However, I strongly recommend that you don’t do that unless you know what you’re doing and you lock down access to sensitive API endpoints.
I was looking to avoid providing my IP because it’s dynamic. Anyway i could use the peer ID to achieve that?
If you’re willing to bundle js-libp2p with your app so your app can connect to a libp2p node, yes (in theory) by using the ipfs p2p
command to forward inbound libp2p streams on some custom protocol back to your IPFS API.
However, at that point, you might as well just bundle js-ipfs with your app.
Is there an example you can point to? I couldn’t find any. Thank you for your time.
An example for using js-ipfs?
In terms of accessing the IPFS API over libp2p, you can technically do that but that’s probably not what you want to do. Could you describe your app/use-case?
My app is basically a form where user can upload some files. My app is hosted on the ipfs node i want to upload the files to. On submit the script would upload the images files to that same node. So i can host them myself.
Personally, I’d use pubsub in this case. Your upload servers listen on
some pubsub channel (ipfs pubsub sub NAME
) and pin anything sent to
this channel. Your app would add the content using js-ipfs, connect to
your upload server using libp2p, then publish the CID of the added
content on the chosen pubsub channel.
However, this isn’t going to be as simple as following a tutorial and
whipping up a quick app. The ecosystem simply isn’t that mature.
Yes the more I look into it the more I realize it. But I was looking at IPNS. Could I upload to my IPNS? because it’s already pointing to my peer ID.