From 373348e46b55030ff59d288e43cd2111402a215a Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 26 May 2021 09:28:00 +0100 Subject: [PATCH] docs: change JS client docs to use metadata API (#149) refs https://github.com/ipfs-shipyard/nft.storage/issues/115 --- packages/client/README.md | 20 +++++++++++++++++--- packages/website/pages/index.js | 21 ++++++++------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/packages/client/README.md b/packages/client/README.md index 929c1bbabf..20fc2f7570 100644 --- a/packages/client/README.md +++ b/packages/client/README.md @@ -28,16 +28,30 @@ yarn add nft.storage First, obtain an API token from https://nft.storage and use it in place of `API_TOKEN` below: ```js -import { NFTStorage } from 'nft.storage' +import { NFTStorage, File } from 'nft.storage' const client = new NFTStorage({ token: API_TOKEN }) -const cid = await client.storeBlob(new Blob(['hello world'])) + +const metadata = await client.store({ + name: 'Pinpie', + description: 'Pin is not delicious beef!', + image: new File( + [ + /* data */ + ], + 'pinpie.jpg', + { type: 'image/jpg' } + ), +}) +console.log(metadata.url) +// ipfs://bafyreib4pff766vhpbxbhjbqqnsh5emeznvujayjj4z2iu533cprgbz23m/metadata.json ``` -For more examples please see the [API documentation][]. +For more examples please see the [API documentation][] or the [examples directory](). [raw http api]: https://nft.storage/#api-docs [node.js]: https://nodejs.org/ [api documentation]: https://ipfs-shipyard.github.io/nft.storage/client/ +[examples directory]: https://github.com/ipfs-shipyard/nft.storage/tree/main/packages/client/examples [ci.icon]: https://github.com/ipfs-shipyard/nft.storage/actions/workflows/client.yml/badge.svg [version.icon]: https://img.shields.io/npm/v/nft.storage.svg [package.url]: https://npmjs.org/package/nft.storage diff --git a/packages/website/pages/index.js b/packages/website/pages/index.js index 1355b5626f..b4cc800584 100644 --- a/packages/website/pages/index.js +++ b/packages/website/pages/index.js @@ -175,19 +175,18 @@ function About() { } function GettingStarted() { - const jsEx = `import { NFTStorage, Blob } from 'nft.storage' + const jsEx = `import { NFTStorage, File } from 'nft.storage' const apiKey = 'YOUR_API_KEY' const client = new NFTStorage({ token: apiKey }) -const content = new Blob(['hello world']) -const cid = await client.storeBlob(content) -console.log(cid)` - - const jsDirEx = `const cid = await client.storeDirectory([ - new File(['hello world'], 'content.txt'), - new File([JSON.stringify({ owner: '@lucky' })], 'metadata.json') -])` +const metadata = await client.store({ + name: 'Pinpie', + description: 'Pin is not delicious beef!', + image: new File([/* data */], 'pinpie.jpg', { type: 'image/jpg' }) +}) +console.log(metadata.url) +// ipfs://bafyreib4pff766vhpbxbhjbqqnsh5emeznvujayjj4z2iu533cprgbz23m/metadata.json` const curlEx = `curl -X POST --data-binary @art.jpg -H 'Authorization: Bearer YOUR_API_KEY' https://api.nft.storage/upload` @@ -277,10 +276,6 @@ console.log(cid)`
               {jsEx}
             
-

The client can also store directories:

-
-              {jsDirEx}
-            

View the{' '}