-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alan Shaw
authored
Nov 16, 2021
1 parent
499fcb5
commit f64d032
Showing
2 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters