1

I want to upload a directory to ipfs on my browser using (js-ipfs-http-client) module. I found this old issue. https://github.com/ipfs/js-ipfs/issues/277 So I decided to use recursive way to add files and get only one hash for it.

ipfs.addFromFs('path', { recursive: true, ignore: ['subfolder/to/ignore/**'] }, (err, result) => {
            if (err) { throw err }
            console.log(result)
        })

But it gave me this error.

enter image description here

I need to upload a directory to ipfs using javascript but all resources I had found upload only one file.Or a lot of files with array of hashes. I need a way to upload all files of directory and get the with only one hash. Thanks in advance.

2 Answers 2

0

I think the issue is that you're trying to call functions from the fs module client-side rather than server-side.

1
  • I know but it's required to use solidity only on the backend. And js will used for fronted. I had already used cdn for fs module and it's working. Commented Aug 11, 2019 at 17:40
0

According to the issue you linked, it looks like the core module does not handle reading files from your system.

Instead, you must pass in a stream of files that IPFS can consume from.

Since you are doing this in the browser, it is a little more complicated to achieve.

Perhaps you might want to look into the FileSystem Access API, which offers the showDirectoryPicker functionality.

From there, you'll have to figure out how to pass these files into IPFS.

Unfortunately, this API doesn't have great browser support at the moment, although that is likely to improve with time. It is still experimental technology.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.