Skip to content

Instantly share code, notes, and snippets.

@krogla
Created January 28, 2022 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krogla/882a699cd43c6e2ac459b11ecb431eb1 to your computer and use it in GitHub Desktop.
Save krogla/882a699cd43c6e2ac459b11ecb431eb1 to your computer and use it in GitHub Desktop.
const { create, globSource } = require('ipfs-http-client')
const globSourceOptions = {
recursive: true
}
const addOptions = {
pin: true,
wrapWithDirectory: true,
timeout: 10000
}
async function uploadDirToIpfs({ apiUrl, dirPath }) {
const ipfs = await create(apiUrl)
const results = []
for await (const result of ipfs.addAll(globSource(dirPath, '*', globSourceOptions), addOptions)) {
results.push(result)
}
return results.find((r) => r.path === '').cid.toString()
}
module.exports = { uploadDirToIpfs }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment