Update content on IPFS

Hi there,

I am working on an app that allows users to share files with their friends. I use orbitdb to store IPNS hashes for mutability. The access control works with asymetric encryption and every “file” has the following structure

/data
-> this file is encrypted with symetric encryption

/dataKeys/some-hash-1
/dataKeys/some-hash-2
/dataKeys/some-hash-3
-> those files contain the symetric key encrypted with the public key of every device that can read the file

/ipnsKeys/some-hash-1
/ipnsKeys/some-hash-2
/ipnsKeys/some-hash-3
-> those files contain the ipns private key encrypted with the public key of every device that can write to the file

I have no problem adding this to ipfs, but I have a concern on how to update a file.

There are 2 basic scenarios of updates:

  1. The file itself changes, this means updating the /data file, since the keys can stay the same
  2. Giving a user the ability to read/write to the file, where there is a new key added to one of the key directories /dataKeys/some-new-hash or /ipnsKeys/some-new-hash

Lets take example 2: How can I add a new key without uploading all other keys and the data file again? (Thats the main question, because with large files or many keys this will take a while and even consume a lot of data if you are on mobile)

I know that the ipfs hash changes due to how the content addressable web works, thats why I use IPNS to store the new hash after each update.

Right now I use ipfs.add to upload the file and I read the docs about the mutable file system, but the write/rm/… methods seam only to work with paths like /some/path/… and not with ipfs hashes.

I hope someone can help me clean up my confusion :slight_smile:

Daniel

Hi Totem,
I have the same issue here, if you have a solution in the meantime let me know plz…
What I understand about it till now is that the files-api (MFS) can be used if you want to assemble (and in this process of assembly you can rename or remove or move your files etc.) a file-stucture. When you are done you can get the CIDhash with ipfs.files.stat. (you can get the hash so easily because the files-api (MFS) is connected to the (regular) files-api, so what is saved in MFS is also put on IPFS automatically).
If you want to change something later, this is not easy/possible. I would think you have to first fetch the files from IPFS to put them in MFS (I didn’t figure out how that is possible (I have tried .read .cat and .get and they all do not save the files in the MFS “sandbox”)

The object-api can be used to make a data-structure (dag IPLD). In the structure you can put nodes containing property values and/or links to another node. I understand there is a 4mb size limit to files you ad with a buffer (I got this answer from Volker last time). Maybe we can get around this by creating a separate file cid first, and then ad it to the data-structure. Never mind… with the object.patch.setData you can update your property values and get a the hash back without having to download the whole data-structure.

I hope this can help anyone :slight_smile: