Upload a JSON object to Pinata

Usage

import { PinataSDK } from "pinata";

const pinata = new PinataSDK({
  pinataJwt: process.env.PINATA_JWT!,
  pinataGateway: "example-gateway.mypinata.cloud",
});

const upload = await pinata.upload.json({
    content: "console.log('hello world!)",
    name: "helloworld.ts",
    lang: "ts"
})

Returns

type UploadResponse = {
	id: string;
	name: string;
	cid: string;
	size: number;
	number_of_files: number;
	mime_type: string;
	user_id: string;
};

Parameters

JSON

  • Type: Record<string, unknown>

Accepts an object that is turned into JSON

const upload = await pinata.upload.json({
    content: "console.log('hello world!)",
    name: "helloworld.ts",
    lang: "ts"
})

group (Optional)

  • Type: string

Upload to a specific group by passing in the groupId

const upload = await pinata.upload
  .json({
      content: "console.log('hello world!)",
      name: "helloworld.ts",
      lang: "ts"
  })
  .group("b07da1ff-efa4-49af-bdea-9d95d8881103")

addMetadata (Optional)

Add optional metadata to file

const upload = await pinata.upload
  .json({
      content: "console.log('hello world!)",
      name: "helloworld.ts",
      lang: "ts"
  })
  .addMetadata({
    name: "hello.json",
    keyvalues: {
      env: "prod"
    }
  })

vectorize (Optional)

The file vectors feature is still in beta. Please contact the team at [email protected] if you have any issues.

  • Type: null

Vectorize a file on upload, requires a group to be used as well.

const upload = await pinata.upload
  .json({
      content: "console.log('hello world!)",
      name: "helloworld.ts",
      lang: "ts"
  })
  .group("b07da1ff-efa4-49af-bdea-9d95d8881103")
  .vectorize()

url (Optional)

  • Type: string

Pass in a presigned upload URL created with createSignedURL

const upload = await pinata.upload
  .json({
    content: "console.log('hello world!)",
    name: "helloworld.ts",
    lang: "ts"
  })
  .url(url)

key (Optional)

  • Type: string

Upload a file using a secondary API key generated through keys.create()

const upload = await pinata.upload
    .json({
        content: "console.log('hello world!)",
        name: "helloworld.ts",
        lang: "ts"
    })
  .key("GENERATED_API_JWT")