-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy pathstoreBlob.js
More file actions
28 lines (25 loc) · 866 Bytes
/
storeBlob.js
File metadata and controls
28 lines (25 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 })
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()