web3-storage / web3.storage

DEPRECATED ⁂ The simple file storage service for IPFS & Filecoin
https://web3.storage
Other
503 stars 119 forks source link

f.stream is not a function #805

Closed user3470 closed 2 years ago

user3470 commented 2 years ago

image

Can someone provide NodeJs example in the docs please

user3470 commented 2 years ago

Had to do

const { File } = require("web3.storage");
johnwwk commented 2 years ago

how did you upload? What's written in docs for node doesn't work at all and gives out this error.

johnwwk commented 2 years ago

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}`)  
}