I’m not good with javascript. I’m trying to upload a few files to nft.storage as a folder by modifying this example → nft.storage/storeDirectory.js at main · nftstorage/nft.storage · GitHub
Instead of uploading via a form, my files are stored in my PC file system. Below is my js code.
<script type="module">
import { NFTStorage, File } from 'https://cdn.skypack.dev/nft.storage'
import { fs } from 'https://cdn.skypack.dev/fs-'
const endpoint = 'https://api.nft.storage' // the default
const token = 'RDA0NjI0MTIzMTA2Mzgy....' // your API key from https://nft.storage/manage
function log(msg) {
msg = JSON.stringify(msg, null, 2)
document.getElementById('out').innerHTML += `${msg}\n`
}
document.querySelector('#upload-file-ipfs').addEventListener('click', async (e) => {
e.preventDefault()
const storage = new NFTStorage({ endpoint, token })
const cid = await storage.storeDirectory([
new File([await fs.promises.readFile('metadata.json')], 'metadata.json'),
new File([await fs.promises.readFile('test.png')], 'test.png'),
])
console.log({ cid })
const status = await storage.status(cid)
console.log(status)
})
</script>
But I keep getting this error below.
Uncaught SyntaxError: The requested module 'https://cdn.skypack.dev/fs-' does not provide an export named 'fs'
I tried replacing ‘https://cdn.skypack.dev/fs-’ with ‘npm:fs-extra | Skypack’ and '‘https://cdn.skypack.dev/graceful-fs’ and it gives me the same error.
If I remove the curly braces around ‘fs’, I get Uncaught Error: [Package Error] "fs" does not exist. (Imported by "fs-").
Any help is highly appreciated.