Skip to content

Commit

Permalink
docs: add encodeBlob example (#791)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw authored Nov 16, 2021
1 parent 499fcb5 commit f64d032
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/client/examples/node.js/encodeBlob.js
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion packages/client/examples/node.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit f64d032

Please sign in to comment.