diff --git a/examples/client/node.js/storeBlob.js b/examples/client/node.js/storeBlob.js index c32eb4b2e8..be5ee80a6e 100644 --- a/examples/client/node.js/storeBlob.js +++ b/examples/client/node.js/storeBlob.js @@ -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()