The only answers I can find in my research cover uploading multiple files from a directory on a PC. That is not what I'm trying to do. I'm trying to create a directory in ipfs and then add new files to that directory using js-ipfs with pure javascript only, generally one file at a time.
I conceptually understand that a directory in ipfs is simply another file. But I don't understand how to create that directory (file) and add other files to it for later retrieval, particularly with js-ipfs and pure javascript code.
I am implicitly not using node.js, therefore neither react, angular or vue either.
This works for a single file with no directory on ipfs:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/ipfs/dist/index.min.js"></script>
</head>
<script>
document.addEventListener('DOMContentLoaded', async () => {
const nodeId = 'ipfs-' + Math.random()
const node = await Ipfs.create({ repo: nodeId })
console.log("Your node: " + nodeId)
window.node = node
const status = node.isOnline() ? 'online' : 'offline'
console.log(`Node status: ${status}`)
async function addFile () {
for await (const { cid } of node.add('Some file content!')) {
console.log('successfully stored', cid)
cidhash=cid.toBaseEncodedString()
console.log(cidhash)
}
}
addFile()
})
</script>
<body>
</body>
</html>
How to make this work to create a directory and add a file to it initially, then add another file to the created directory later (pseudocode-ish)?
async function addFile () {
for await (const { directory, filename } of node.add('/someDirectory/someFilename','Some file content!')) {
console.log('successfully stored', directory, filename)
console.log(directory, filename)
}
}