Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions examples/client/node.js/storeBlob.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@ const token = 'API_KEY' // your API key from https://nft.storage/manage

async function main() {
const storage = new NFTStorage({ endpoint, token })
const data = await fs.promises.readFile('pinpie.jpg')
const cid = await storage.storeBlob(new Blob([data]))
console.log({ cid })
const status = await storage.status(cid)
console.log(status)
let data = ""
const readStream = fs.createReadStream('pinpie.jpg')
// on data will receive data from the stream and concatenate it to the variable data
readStream.on('data', (chunk) => {
data += chunk
})
// on end will finish the stream
readStream.on('end', async () => {
const cid = await storage.storeBlob(new Blob([data]))
console.log({ cid })
const status = await storage.status(cid)
console.log(status)
})
// on error will show what happened if something goes wrong
readStream.on('error', (error) => {
console.log({ error })
})

}
main()