diff --git a/packages/client/examples/node.js/encodeBlob.js b/packages/client/examples/node.js/encodeBlob.js new file mode 100644 index 0000000000..a00847a282 --- /dev/null +++ b/packages/client/examples/node.js/encodeBlob.js @@ -0,0 +1,20 @@ +import fs from 'fs' +import { NFTStorage, Blob } from 'nft.storage' + +const endpoint = 'https://api.nft.storage' // the default +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, car } = await NFTStorage.encodeBlob(new Blob([data])) + console.log(`File CID: ${cid}`) + + console.log('Sending file...') + await storage.storeCar(car, { + onStoredChunk: (size) => console.log(`Stored a chunk of ${size} bytes`), + }) + + console.log('✅ Done') +} +main() diff --git a/packages/client/examples/node.js/package.json b/packages/client/examples/node.js/package.json index 36c122f055..138ee95bf0 100644 --- a/packages/client/examples/node.js/package.json +++ b/packages/client/examples/node.js/package.json @@ -12,6 +12,6 @@ "license": "(Apache-2.0 AND MIT)", "dependencies": { "ipfs-car": "^0.5.8", - "nft.storage": "^3.3.0" + "nft.storage": "^4.0.0" } }