Upload
json
Upload a JSON object to Pinata
Usage
import { PinataSDK } from "pinata-web3";
const pinata = new PinataSDK({
pinataJwt: process.env.PINATA_JWT!,
pinataGateway: "example-gateway.mypinata.cloud",
});
const upload = await pinata.upload.json({
name: "Pinnie NFT",
description: "A Pinnie NFT from Pinata",
image: "ipfs://bafkreih5aznjvttude6c3wbvqeebb6rlx5wkbzyppv7garjiubll2ceym4"
})
Returns
type PinResponse = {
IpfsHash: string;
PinSize: number;
Timestamp: string;
isDuplicate?: boolean;
};
Parameters
JSON
- Type:
Record<string, unknown>
Accepts an object that is turned into JSON
const upload = await pinata.upload.json({
name: "Pinnie NFT",
description: "A Pinnie NFT from Pinata",
image: "ipfs://bafkreih5aznjvttude6c3wbvqeebb6rlx5wkbzyppv7garjiubll2ceym4",
attributes: [
{
name: "whimsey",
value: 100
}
]
})
addMetadata (Optional)
- Type: PinataMetadata
Add optional metadata to file
const upload = await pinata.upload
.json({
name: "Pinnie NFT",
description: "A Pinnie NFT from Pinata",
image: "ipfs://bafkreih5aznjvttude6c3wbvqeebb6rlx5wkbzyppv7garjiubll2ceym4"
})
.addMetadata({
name: "pinnie.png",
keyValues: {
whimsey: 100
}
})
group (Optional)
- Type:
string
Upload to a specific group by passing in the groupId
const upload = await pinata.upload
.json({
name: "Pinnie NFT",
description: "A Pinnie NFT from Pinata",
image: "ipfs://bafkreih5aznjvttude6c3wbvqeebb6rlx5wkbzyppv7garjiubll2ceym4"
})
.group("b07da1ff-efa4-49af-bdea-9d95d8881103")
key (Optional)
- Type:
string
Upload a file using a secondary API key generated through keys.create()
const upload = await pinata.upload
.json({
name: "Pinnie NFT",
description: "A Pinnie NFT from Pinata",
image: "ipfs://bafkreih5aznjvttude6c3wbvqeebb6rlx5wkbzyppv7garjiubll2ceym4"
})
.key("GENERATED_API_JWT")
cidVersion (Optional)
- Type:
0 | 1
Specificy CID version for upload
const upload = await pinata.upload
.json({
name: "Pinnie NFT",
description: "A Pinnie NFT from Pinata",
image: "ipfs://bafkreih5aznjvttude6c3wbvqeebb6rlx5wkbzyppv7garjiubll2ceym4"
})
.cidVersion(0)