Closed user3470 closed 2 years ago
Had to do
const { File } = require("web3.storage");
how did you upload? What's written in docs for node doesn't work at all and gives out this error.
this works:
const { Web3Storage, File,Blob, getFilesFromPath } = require("web3.storage");
//for path/api files such as nft image
const carFiles = await getFilesFromPath(file.filepath);
const rootCid = await web3StorageClient.put(carFiles);
//for json files such as nft metadata
const blob = new Blob([JSON.stringify(metadata)], {type : 'application/json'})
const files = [new File([blob], 'metadata.json')]
const rootCid = await web3StorageClient.put(files)
const resx = await web3StorageClient.get(rootCid)
const filesx = await resx.files()
var uploadedFileUrls = []
for (const file of filesx) {
console.log(`File Info: ${file.cid} ${file.name} ${file.size}`)
}
Can someone provide NodeJs example in the docs please