IPFS: How to add a file to an existing folder?

IDon'tUnderstandOOP picture IDon'tUnderstandOOP · Oct 1, 2016 · Viewed 7.8k times · Source

Given a rather large folder, that has already been pushed to the network, and deleted locally. How would a file be added to that folder, without re-downloading the entire folder it?

Answer

JayB picture JayB · May 10, 2017

You can only do it by using ipns after downloading it again with ipfs get, which should be fast if it's still pinned to your local storage:

(1) first add (i.e. re-add) your folder to ipfs recursively: ipfs add -r /path/to/folder. The second column of the last stdout line has the ipfs hash of the parent folder you just added. (The original files are still the same, so the hashes will be the same too.)

(2) then publish that hash: ipfs name publish /ipfs/<CURRENT_PARENTFOLDER_HASH>. This will return your peer ID, and you can share the link as /ipns/<PEER_ID>; repeat this step (ipfs name publish) whenever the folder contents (and therefore the parent folder hash) changes. The ipns object will then always point to the latest version of your folder.

(3) if you plan on sharing a lot, you can create a new keypair for each folder you share: ipfs key gen --type=rsa --size=2048 new-share-key … and then use that key (instead of your default key) to publish (and later republish) that folder: ipfs name publish --key=new-share-key /ipfs/<CURRENT_PARENTFOLDER_HASH>

See also the documentation here: https://docs.ipfs.io/reference/cli/#ipfs-name-publish