How to add multiple files to IPFS Mutable Files System without revealing the content to the IPFS network

Viewed 27

I need to be able to add a bunch of files to a common directory using the mutable file system from ipfs.files.* without revealing this content to the IPFS network until it is needed.

This is the code I have been using to test:

  const onDrop = useCallback(async (acceptedFiles) => {
    const test = JSON.stringify({test:"test"});
    const testFile = new File([test], "test.json")

    try{
      for(let i = 0; i < acceptedFiles.length; i++){
        console.log(acceptedFiles[i].path)
        await ipfs.files.write(files[i].path, files[i], {parents: true})
    }

    await ipfs.files.write("/test.json", [testFile], { create: true })

    } catch(e){
      console.log(e)
    }

   console.log((await ipfs.files.stat( "/" )).cid.toV1().toString())
  }, [])

This throws me the error:

ReferenceError: global is not defined
    at toAsyncIterator (to-async-iterator.js?6924:44:1)
    at eval (write.js?db08:99:37)
    at eval (create-lock.js?5096:33:1)
    at async mfsWrite (write.js?db08:98:1)

caused by the ipfs.files.wite() statement in the loop.

I initially added content through the ipfs.addAll() function, but this did not seem to work for adding it to the global MFS directory.

I think I am using the documentation right, but I might be trying to use MFS for something it was not intended for. If anyone knows the best way to achieve combining many files into a directory without revealing the content to the IPFS network, please let me know.

0 Answers
Related