### Run Project with Bun Source: https://github.com/pinatacloud/pinata/blob/main/examples/playground/README.md This command executes the main project file (index.ts) using the Bun runtime. This is used to start the application after dependencies have been installed. ```bash bun run index.ts ``` -------------------------------- ### Install Dependencies with Bun Source: https://github.com/pinatacloud/pinata/blob/main/examples/playground/README.md This command installs all necessary project dependencies using the Bun package manager. Ensure Bun is installed on your system before running this command. ```bash bun install ``` -------------------------------- ### Install Pinata SDK Source: https://github.com/pinatacloud/pinata/blob/main/README.md Install the Pinata SDK using npm. This is the first step to integrate Pinata services into your project. ```bash npm i pinata ``` -------------------------------- ### Clone and Build Pinata Repository Source: https://github.com/pinatacloud/pinata/blob/main/README.md Clone the Pinata GitHub repository, install dependencies, and run the build script to prepare the project for development. ```bash git clone https://github.com/PinataCloud/pinata cd pinata npm install npm run build ``` -------------------------------- ### Run Tests for Pinata Project Source: https://github.com/pinatacloud/pinata/blob/main/README.md Execute the test suite for the Pinata project using the npm test command after installation and building. ```bash npm run test ``` -------------------------------- ### Integrate React-Specific ESLint Plugins (React) Source: https://github.com/pinatacloud/pinata/blob/main/examples/vite-react/README.md This code demonstrates how to integrate `eslint-plugin-react-x` and `eslint-plugin-react-dom` into your ESLint configuration. It adds these plugins and enables their recommended TypeScript and DOM-specific rules for improved React linting. ```javascript // eslint.config.js import reactX from 'eslint-plugin-react-x' import reactDom from 'eslint-plugin-react-dom' export default tseslint.config({ plugins: { // Add the react-x and react-dom plugins 'react-x': reactX, 'react-dom': reactDom, }, rules: { // other rules... // Enable its recommended typescript rules ...reactX.configs['recommended-typescript'].rules, ...reactDom.configs.recommended.rules, }, }) ``` -------------------------------- ### Retrieve File Content from IPFS Source: https://context7.com/pinatacloud/pinata/llms.txt Retrieves the content of a file from IPFS using its CID. This example first uploads a text file to get a CID, then converts it to a gateway URL, and finally fetches the file's content. The returned content includes the data and its MIME type. ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function getFileContent() { try { const uuid = crypto.randomUUID(); const upload = await pinata.upload.public.file( new File([uuid], `${uuid}.txt`, { type: "text/plain" }) ); const url = await pinata.gateways.public.convert(upload.cid); console.log(url); const content = await pinata.gateways.public.get(upload.cid); console.log(content); // Returns: { data, contentType } } catch (error) { console.log(error); } } getFileContent(); ``` -------------------------------- ### Configure ESLint with Type-Aware Lint Rules (TypeScript) Source: https://github.com/pinatacloud/pinata/blob/main/examples/vite-react/README.md This snippet shows how to configure ESLint to enable type-aware linting rules in a TypeScript project. It extends recommended type-checked, strict type-checked, and stylistic type-checked configurations. Ensure `tsconfig.node.json` and `tsconfig.app.json` are correctly specified for project parsing. ```javascript export default tseslint.config({ extends: [ // Remove ...tseslint.configs.recommended and replace with this ...tseslint.configs.recommendedTypeChecked, // Alternatively, use this for stricter rules ...tseslint.configs.strictTypeChecked, // Optionally, add this for stylistic rules ...tseslint.configs.stylisticTypeChecked, ], languageOptions: { // other options... parserOptions: { project: ['./tsconfig.node.json', './tsconfig.app.json'], tsconfigRootDir: import.meta.dirname, }, }, }) ``` -------------------------------- ### Get File Content Source: https://context7.com/pinatacloud/pinata/llms.txt Retrieve file content from IPFS using CID. ```APIDOC ## Get File Content ### Description Retrieve file content from IPFS using CID. ### Method GET ### Endpoint /pinata/gateways/public/get/:cid /pinata/gateways/private/get/:cid ### Parameters #### Path Parameters - **cid** (string) - Required - The Content Identifier (CID) of the file to retrieve. #### Query Parameters None #### Request Body None ### Request Example ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function getFileContent() { try { const uuid = crypto.randomUUID(); const upload = await pinata.upload.public.file( new File([uuid], `${uuid}.txt`, { type: "text/plain" }) ); const url = await pinata.gateways.public.convert(upload.cid); console.log(url); const content = await pinata.gateways.public.get(upload.cid); console.log(content); } catch (error) { console.log(error); } } getFileContent(); ``` ### Response #### Success Response (200) - **data** (Buffer) - The content of the file. - **contentType** (string) - The MIME type of the file. #### Response Example ```json { "data": "", "contentType": "text/plain" } ``` ``` -------------------------------- ### GET /analytics/requests/days Source: https://context7.com/pinatacloud/pinata/llms.txt Retrieves gateway usage analytics, including request counts and bandwidth usage over a specified number of days. ```APIDOC ## GET /analytics/requests/days ### Description Tracks gateway usage with requests and bandwidth analytics. ### Method GET ### Endpoint /analytics/requests/days ### Parameters #### Path Parameters - **days** (integer) - Required - The number of days for the analytics. #### Query Parameters - **referer** (boolean) - Optional - To filter by referer. - **limit** (integer) - Optional - Limit the results. ### Request Example ```json { "days": 7 } ``` ### Response #### Success Response (200) - **data** (array) - An array of analytics data. #### Response Example ```json { "data": [ { "value": "2024-10-20", "requests": 100, "bandwidth": 1024000 } ] } ``` ``` -------------------------------- ### Get Gateway Analytics with Pinata SDK Source: https://context7.com/pinatacloud/pinata/llms.txt Retrieves analytics data for Pinata gateway usage, specifically tracking requests and bandwidth over a specified period. This function utilizes the Pinata SDK and requires authentication. It allows filtering by referer and limiting the number of results returned. ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function getAnalytics() { try { const clicks = await pinata.analytics.requests.days(7).referer().limit(5); console.log(clicks); // Returns: { data: [{ value, requests, bandwidth }] } } catch (error) { console.log(error); } } getAnalytics(); ``` -------------------------------- ### SDK Initialization Source: https://context7.com/pinatacloud/pinata/llms.txt Initialize the Pinata SDK with your JWT token and optional gateway configuration. ```APIDOC ## SDK Initialization ### Description Initialize the Pinata SDK with your JWT token and optional gateway configuration. ### Method Constructor ### Endpoint N/A ### Parameters #### Constructor Parameters - **pinataJwt** (string) - Required - Your Pinata JWT token. - **pinataGateway** (string) - Optional - Your custom Pinata gateway URL. ### Request Example ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "example-gateway.mypinata.cloud" }); // Test authentication try { const result = await pinata.testAuthentication(); console.log(result); } catch (error) { console.error("Authentication failed:", error); } ``` ### Response #### Success Response (200) An object indicating successful authentication. #### Response Example ```json { "message": "JWT claims verified successfully" } ``` ``` -------------------------------- ### Initialize Pinata SDK Source: https://github.com/pinatacloud/pinata/blob/main/README.md Initialize the Pinata SDK with your API Key JWT and Gateway Domain. Ensure sensitive keys are handled securely. ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: "PINATA_JWT", pinataGateway: "example-gateway.mypinata.cloud", }); ``` -------------------------------- ### POST /keys Source: https://context7.com/pinatacloud/pinata/llms.txt Creates a scoped API key with specified permissions. Allows setting specific access rights for the API key. ```APIDOC ## POST /keys ### Description Creates a scoped API key with specified permissions. ### Method POST ### Endpoint /keys ### Parameters #### Request Body - **keyName** (string) - Required - The name of the API key. - **permissions** (object) - Required - The permissions to assign to the key. ### Request Example ```json { "keyName": "read-only", "permissions": { "resources": ["org:files:read"] } } ``` ### Response #### Success Response (200) - **JWT** (string) - The JWT for the new API key. #### Response Example ```json { "JWT": "your_api_key_jwt" } ``` ``` -------------------------------- ### List and Convert Files using Pinata SDK Source: https://context7.com/pinatacloud/pinata/llms.txt Lists files stored on Pinata's public network with support for pagination using the `limit` method. It also demonstrates converting a file's CID into a gateway URL for access. The `listFiles` function retrieves file objects, and `convert` generates a shareable link. ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function listFiles() { try { const files = await pinata.files.public.list().limit(1); console.log(files.files); // Returns array of file objects with metadata // Convert CID to gateway URL const link = await pinata.gateways.public.convert(files.files[0].cid); console.log(link); } catch (error) { console.log(error); } } listFiles(); ``` -------------------------------- ### List Files Source: https://context7.com/pinatacloud/pinata/llms.txt List and filter files with pagination support. ```APIDOC ## List Files ### Description List and filter files with pagination support. ### Method GET ### Endpoint /pinata/files/public /pinata/files/private ### Parameters #### Path Parameters None #### Query Parameters - **limit** (integer) - Optional - The maximum number of files to return. - **offset** (integer) - Optional - The number of files to skip before returning results. - **metadata** (object) - Optional - Filters based on metadata key-value pairs. ### Request Example ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function listFiles() { try { const files = await pinata.files.public.list().limit(1); console.log(files.files); const link = await pinata.gateways.public.convert(files.files[0].cid); console.log(link); } catch (error) { console.log(error); } } listFiles(); ``` ### Response #### Success Response (200) - **files** (array) - An array of file objects, each containing: - **id** (string) - The unique identifier for the file. - **name** (string) - The name of the file. - **cid** (string) - The Content Identifier (CID) of the file on IPFS. - **size** (integer) - The size of the file in bytes. - **created_at** (string) - The timestamp when the file was created. - **keyvalues** (object) - Key-value pairs associated with the file. #### Response Example ```json { "files": [ { "id": "example-file-id", "name": "example.json", "cid": "Qmexamplecid", "size": 1024, "created_at": "2023-10-27T10:00:00.000Z", "keyvalues": { "env": "prod" } } ] } ``` ``` -------------------------------- ### Initialize Pinata SDK with JWT Source: https://context7.com/pinatacloud/pinata/llms.txt Initializes the Pinata SDK using a JWT token for authentication and an optional custom gateway configuration. This is the first step before performing any operations with the SDK. Ensure the PINATA_JWT environment variable is set. ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "example-gateway.mypinata.cloud" }); // Test authentication try { const result = await pinata.testAuthentication(); console.log(result); } catch (error) { console.error("Authentication failed:", error); } ``` -------------------------------- ### Upload from URL Source: https://context7.com/pinatacloud/pinata/llms.txt Upload content directly from a URL to IPFS. ```APIDOC ## Upload from URL ### Description Upload content directly from a URL to IPFS. ### Method POST ### Endpoint /pinata/upload/public/url /pinata/upload/private/url ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **url** (string) - Required - The URL of the content to upload. - **keyvalues** (object) - Optional - Key-value pairs for metadata. ### Request Example ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function uploadFromUrl() { try { const data = await pinata.upload.public .url("https://i.imgur.com/u4mGk5b.gif") .keyvalues({ name: "upload url test" }); console.log(data); } catch (error) { console.log(error); } } uploadFromUrl(); ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the pinned content. - **cid** (string) - The Content Identifier (CID) of the content on IPFS. - **name** (string) - The name of the uploaded content. - **keyvalues** (object) - Key-value pairs associated with the content. #### Response Example ```json { "id": "example-url-upload-id", "cid": "Qmexampleurlcid", "name": "u4mGk5b.gif", "keyvalues": { "name": "upload url test" } } ``` ``` -------------------------------- ### Create API Key with Pinata SDK Source: https://context7.com/pinatacloud/pinata/llms.txt Creates a new API key with specific permissions for accessing Pinata resources. This function uses the Pinata SDK and requires existing authentication. It defines key permissions, creates the key, and demonstrates using the new key to list files and groups. ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function createApiKey() { try { const readKey = await pinata.keys.create({ keyName: "read-only", permissions: { resources: ["org:files:read"] } }); // Use the new key pinata.setNewJwt(readKey.JWT); const files = await pinata.files.public.list(); console.log(files); const groups = await pinata.groups.public.list(); console.log(groups); } catch (error) { console.log(error); } } createApiKey(); ``` -------------------------------- ### Add EIP-712 Signature to File Upload using Pinata SDK and Viem Source: https://context7.com/pinatacloud/pinata/llms.txt This TypeScript code snippet demonstrates how to upload a file to Pinata, generate an EIP-712 signature for it using Viem, and then add that signature to the file's metadata on Pinata. It requires Pinata JWT, private key, and address environment variables. The function first uploads a random file, signs its CID with user-provided credentials, adds the signature to Pinata, and then retrieves the signature. ```typescript import { PinataSDK } from "pinata"; import { createWalletClient, http } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { mainnet } from "viem/chains"; const walletClient = createWalletClient({ chain: mainnet, transport: http() }); const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); const domain = { name: "Sign", version: "1.0.0", chainId: 1 } as const; const types = { Sign: [ { name: "address", type: "address" }, { name: "cid", type: "string" }, { name: "date", type: "string" } ] }; async function addSignature() { try { const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x`); const uuid = crypto.randomUUID(); const file = new File([uuid], `${uuid}.txt`, { type: "text/plain" }); const upload = await pinata.upload.public.file(file); const signature = await walletClient.signTypedData({ account, domain, types, primaryType: "Sign", message: { address: process.env.ADDRESS, cid: upload.cid, date: Date.now() } }); const sign = await pinata.signatures.public.add({ cid: upload.cid, signature: signature, address: "0x" }); console.log(sign); const getSig = await pinata.signatures.public.get(upload.cid); console.log(getSig); } catch (error) { console.log(error); } } addSignature(); ``` -------------------------------- ### POST /groups/public Source: https://context7.com/pinatacloud/pinata/llms.txt Creates a new group within Pinata Cloud. Groups are used to organize and manage files. ```APIDOC ## POST /groups/public ### Description Creates a new group to help organize files. The API returns information about the newly created group. ### Method POST ### Endpoint /groups/public ### Parameters #### Request Body - **name** (string) - Required - The name of the group. ### Request Example ```json { "name": "my-group" } ``` ### Response #### Success Response (200) - **id** (string) - The ID of the created group. - **name** (string) - The name of the created group. - **is_public** (boolean) - Indicates if the group is public or private. - **created_at** (string) - The timestamp of when the group was created. #### Response Example ```json { "id": "group_id", "name": "my-group", "is_public": true, "created_at": "2024-10-27T10:00:00.000Z" } ``` ``` -------------------------------- ### Upload File Source: https://context7.com/pinatacloud/pinata/llms.txt Upload a single file to Pinata's public or private network with optional metadata. ```APIDOC ## Upload File ### Description Upload a single file to Pinata's public or private network with optional metadata. ### Method POST ### Endpoint /pinata/upload/public/file /pinata/upload/private/file ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **file** (File) - Required - The file to upload. - **keyvalues** (object) - Optional - Key-value pairs for metadata. ### Request Example ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function uploadFile() { try { const uuid = crypto.randomUUID(); const blob = new Blob([JSON.stringify({ text: uuid })]); const file = new File([blob], `${uuid}.json`, { type: "application/json" }); const upload = await pinata.upload.public.file(file).keyvalues({ env: "prod" }); console.log(upload); } catch (error) { console.log(error); } } uploadFile(); ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the pinned file. - **name** (string) - The name of the file. - **cid** (string) - The Content Identifier (CID) of the file on IPFS. - **size** (integer) - The size of the file in bytes. - **created_at** (string) - The timestamp when the file was created. - **number_of_files** (integer) - The number of files included in the upload. - **mime_type** (string) - The MIME type of the file. - **group_id** (string) - The ID of the group the file belongs to. - **keyvalues** (object) - Key-value pairs associated with the file. - **vectorized** (boolean) - Indicates if the file has been vectorized. - **network** (string) - The network the file is pinned to (e.g., "mainnet", "testnet"). #### Response Example ```json { "id": "example-id", "name": "example.json", "cid": "Qmexamplecid", "size": 1024, "created_at": "2023-10-27T10:00:00.000Z", "number_of_files": 1, "mime_type": "application/json", "group_id": null, "keyvalues": { "env": "prod" }, "vectorized": false, "network": "mainnet" } ``` ``` -------------------------------- ### POST /gateways/private/access_links Source: https://context7.com/pinatacloud/pinata/llms.txt Creates temporary access links for private files hosted on Pinata Cloud. These links provide time-limited access to the files. ```APIDOC ## POST /gateways/private/access_links ### Description Generates time-limited access links for private files. ### Method POST ### Endpoint gateways/private/access_links ### Parameters #### Request Body - **cid** (string) - Required - The CID of the file. - **expires** (integer) - Required - The expiration time in seconds. ### Request Example ```json { "cid": "file_cid", "expires": 30 } ``` ### Response #### Success Response (200) - **url** (string) - The signed URL. #### Response Example ```json { "url": "https://your-gateway.pinata.cloud/ipfs/file_cid?signature=...&expires=..." } ``` ``` -------------------------------- ### Upload Base64 Source: https://context7.com/pinatacloud/pinata/llms.txt Upload base64 encoded data to IPFS. ```APIDOC ## Upload Base64 ### Description Upload base64 encoded data to IPFS. ### Method POST ### Endpoint /pinata/upload/public/base64 /pinata/upload/private/base64 ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **base64String** (string) - Required - The base64 encoded string of the data to upload. - **name** (string) - Optional - The name to assign to the uploaded file. ### Request Example ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function uploadBase64() { try { const data = await pinata.upload.public.base64("SGVsbG8gV29ybGQh", "hello.txt"); console.log(data); } catch (error) { console.log(error); } } uploadBase64(); ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the pinned data. - **cid** (string) - The Content Identifier (CID) of the data on IPFS. - **name** (string) - The name of the uploaded file. #### Response Example ```json { "id": "example-base64-id", "cid": "Qmexamplebase64cid", "name": "hello.txt" } ``` ``` -------------------------------- ### Create Signed Upload URL with Pinata SDK Source: https://context7.com/pinatacloud/pinata/llms.txt Generates a secure, time-limited URL for uploading files to Pinata. This method requires the Pinata SDK and authentication. It allows for uploads to a specified group and returns both the signed URL and the result of the upload performed using that URL. ```typescript import { PinataSDK } from "pinata"; import * as crypto from "crypto"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function signedUpload() { try { const uuid = crypto.randomUUID(); const file = new File([uuid], `${uuid}.txt`, { type: "text/plain" }); const signedUrl = await pinata.upload.private.createSignedURL({ expires: 100, groupId: "d28a73ce-e54e-433e-896a-21b2e720d05a" }); console.log(signedUrl); const upload = await pinata.upload.private.file(file).url(signedUrl); console.log(upload); } catch (error) { console.log(error); } } signedUpload(); ``` -------------------------------- ### Create Private Access Link with Pinata SDK Source: https://context7.com/pinatacloud/pinata/llms.txt Generates a temporary, signed URL to access private files hosted on Pinata. This function requires the Pinata SDK and authentication. It takes a file's CID and an expiration time in seconds, returning a URL that grants access for the specified duration. ```typescript import { NetworkError, PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function createAccessLink() { try { const uuid1 = crypto.randomUUID(); const file = new File([uuid1], `file1.txt`, { type: "text/plain" }); const { cid } = await pinata.upload.private.file(file); const url = await pinata.gateways.private.createAccessLink({ cid: cid, expires: 30 }); console.log(url); // Returns signed URL valid for 30 seconds } catch (e) { const error = e as NetworkError; console.log(error); console.log(error.details?.metadata?.headers); } } createAccessLink(); ``` -------------------------------- ### Upload File with Pinata SDK Source: https://github.com/pinatacloud/pinata/blob/main/README.md Upload a file to Pinata using the SDK. This function takes a File object and returns upload details, including the file's CID. ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT!, pinataGateway: "example-gateway.mypinata.cloud", }); async function main() { try { const file = new File(["hello"], "Testing.txt", { type: "text/plain" }); const upload = await pinata.upload.public.file(file); console.log(upload); } catch (error) { console.log(error); } } await main(); ``` -------------------------------- ### Retrieve File with Pinata SDK Source: https://github.com/pinatacloud/pinata/blob/main/README.md Retrieve a file from Pinata using its Content Identifier (CID). This function fetches the file data from the gateway. ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT!, pinataGateway: "example-gateway.mypinata.cloud", }); async function main() { try { const data = await pinata.gateways.public.get("bafkreibm6jg3ux5qumhcn2b3flc3tyu6dmlb4xa7u5bf44yegnrjhc4yeq"); console.log(data) } catch (error) { console.log(error); } } main(); ``` -------------------------------- ### Create File Group with Pinata SDK Source: https://context7.com/pinatacloud/pinata/llms.txt Creates a new group within Pinata for organizing files. This function uses the Pinata SDK and requires authentication. It accepts a group name and returns the details of the newly created group, including its ID and creation timestamp. ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function createGroup() { try { const group = await pinata.groups.public.create({ name: "refactor-test" }); console.log(group); // Returns: { id, name, is_public, created_at } } catch (error) { console.log(error); } } createGroup(); ``` -------------------------------- ### POST /upload/private/signed Source: https://context7.com/pinatacloud/pinata/llms.txt Generates a signed URL for secure file uploads with a defined expiration time. This allows for time-limited, controlled access for uploading files. ```APIDOC ## POST /upload/private/signed ### Description Generates a signed URL with expiration for secure file uploads. ### Method POST ### Endpoint /upload/private/signed ### Parameters #### Request Body - **expires** (integer) - Required - The expiration time in seconds. - **groupId** (string) - Optional - The ID of the group where the file should be uploaded. ### Request Example ```json { "expires": 100, "groupId": "group_id" } ``` ### Response #### Success Response (200) - **url** (string) - The signed URL. #### Response Example ```json { "url": "https://your-gateway.pinata.cloud/some-path?signature=...&expires=..." } ``` ``` -------------------------------- ### Upload JSON Source: https://context7.com/pinatacloud/pinata/llms.txt Upload JSON data directly without creating a file object. ```APIDOC ## Upload JSON ### Description Upload JSON data directly without creating a file object. ### Method POST ### Endpoint /pinata/upload/public/json /pinata/upload/private/json ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **content** (any) - Required - The JSON data to upload. - **metadata** (object) - Optional - Metadata for the JSON object. ### Request Example ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function uploadJson() { try { const upload = await pinata.upload.public.json({ content: { "message": "Hello World!" }, metadata: { timestamp: Date.now() } }); console.log(upload); } catch (error) { console.log(error); } } uploadJson(); ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the pinned JSON. - **cid** (string) - The Content Identifier (CID) of the JSON on IPFS. - **metadata** (object) - Metadata associated with the JSON. #### Response Example ```json { "id": "example-json-id", "cid": "Qmexamplejsoncid", "metadata": { "timestamp": 1678886400000 } } ``` ``` -------------------------------- ### Upload Content from URL to Pinata Source: https://context7.com/pinatacloud/pinata/llms.txt Uploads content directly from a given URL to IPFS via Pinata. This is convenient for importing external resources. The operation supports adding key-value metadata to the uploaded content. ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function uploadFromUrl() { try { const data = await pinata.upload.public .url("https://i.imgur.com/u4mGk5b.gif") .keyvalues({ name: "upload url test" }); console.log(data); } catch (error) { console.log(error); } } uploadFromUrl(); ``` -------------------------------- ### Upload File to Pinata Source: https://context7.com/pinatacloud/pinata/llms.txt Uploads a single file to Pinata's public IPFS network. Supports various file types and allows adding key-value metadata for organization. The function generates a unique file name and returns upload details including the CID. ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function uploadFile() { try { const uuid = crypto.randomUUID(); const blob = new Blob([JSON.stringify({ text: uuid })]); const file = new File([blob], `${uuid}.json`, { type: "application/json" }); const upload = await pinata.upload.public.file(file).keyvalues({ env: "prod" }); console.log(upload); // Returns: { id, name, cid, size, created_at, number_of_files, mime_type, group_id, keyvalues, vectorized, network } } catch (error) { console.log(error); } } uploadFile(); ``` -------------------------------- ### Update File Metadata with Pinata SDK Source: https://context7.com/pinatacloud/pinata/llms.txt Updates the name and key-value metadata for an existing file in Pinata. Requires the Pinata SDK and a valid JWT. It takes a file ID and new metadata as input and returns the update result. ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function updateFile() { try { const uuid = crypto.randomUUID(); const { id } = await pinata.upload.private.file( new File([uuid], `${uuid}.txt`, { type: "text/plain" }) ); const updateFile = await pinata.files.private.update({ id, name: `${uuid}-updated.txt`, keyvalues: { whimsey: "true" } }); console.log(updateFile); } catch (error) { console.log(error); } } updateFile(); ``` -------------------------------- ### DELETE /files/public Source: https://context7.com/pinatacloud/pinata/llms.txt Deletes one or more files from Pinata Cloud by their IDs. Allows the removal of files based on provided identifiers. ```APIDOC ## DELETE /files/public ### Description Deletes one or more files based on their unique identifiers. ### Method DELETE ### Endpoint /files/public ### Parameters #### Request Body - **ids** (array of strings) - Required - An array containing the IDs of the files to delete. ### Request Example ```json { "ids": [ "file_id_1", "file_id_2" ] } ``` ### Response #### Success Response (200) - **id** (string) - The ID of the deleted file. - **status** (string) - The deletion status. #### Response Example ```json [ { "id": "file_id_1", "status": "success" }, { "id": "file_id_2", "status": "success" } ] ``` ``` -------------------------------- ### Upload JSON Data to Pinata Source: https://context7.com/pinatacloud/pinata/llms.txt Uploads JSON data directly to Pinata's public IPFS network without requiring a File object. This is useful for storing configuration or dynamic data. The response includes the CID for accessing the uploaded JSON. ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function uploadJson() { try { const upload = await pinata.upload.public.json({ content: "Hello World!", metadata: { timestamp: Date.now() } }); console.log(upload); // Returns upload response with CID for accessing the JSON } catch (error) { console.log(error); } } uploadJson(); ``` -------------------------------- ### PUT /files/private/update Source: https://context7.com/pinatacloud/pinata/llms.txt Updates the name and metadata of an existing file stored in Pinata Cloud. Allows modification of file properties. ```APIDOC ## PUT /files/private/update ### Description Updates the name and metadata for a specific file, enabling modification of file properties. ### Method PUT ### Endpoint /files/private/update ### Parameters #### Request Body - **id** (string) - Required - The ID of the file to update. - **name** (string) - Optional - The new name for the file. - **keyvalues** (object) - Optional - Metadata to associate with the file. ### Request Example ```json { "id": "file_id", "name": "new_file_name.txt", "keyvalues": { "whimsey": "true" } } ``` ### Response #### Success Response (200) - **id** (string) - The ID of the updated file. - **name** (string) - The new name of the updated file. - **keyvalues** (object) - The metadata associated with the updated file. #### Response Example ```json { "id": "file_id", "name": "new_file_name.txt", "keyvalues": { "whimsey": "true" } } ``` ``` -------------------------------- ### Delete Files with Pinata SDK Source: https://context7.com/pinatacloud/pinata/llms.txt Deletes one or more files from Pinata identified by their IDs. This function utilizes the Pinata SDK and requires authentication. It accepts an array of file IDs and returns an array indicating the status of each deletion. ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function deleteFiles() { try { const del = await pinata.files.public.delete([ "0196ca35-7b3c-76ce-b7ca-ca6675d76bec" ]); console.log(del); // Returns array of deletion results: [{ id, status }] } catch (error) { console.log(error); } } deleteFiles(); ``` -------------------------------- ### Upload Base64 Encoded Data to Pinata Source: https://context7.com/pinatacloud/pinata/llms.txt Uploads base64 encoded data to IPFS. This method is suitable for binary data that has been encoded into a base64 string. The decoded content will be stored on IPFS. ```typescript import { PinataSDK } from "pinata"; const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT, pinataGateway: "" }); async function uploadBase64() { try { const data = await pinata.upload.public.base64("SGVsbG8gV29ybGQh"); console.log(data); // Base64 string "SGVsbG8gV29ybGQh" decodes to "Hello World!" } catch (error) { console.log(error); } } uploadBase64(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.