Created
January 28, 2022 11:35
-
-
Save krogla/882a699cd43c6e2ac459b11ecb431eb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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