Upload an array of files to Pinata as a folder
Usage
import { PinataSDK } from "pinata-web3";
const pinata = new PinataSDK({
pinataJwt: process.env.PINATA_JWT!,
pinataGateway: "example-gateway.mypinata.cloud",
});
const file1 = new File(["hello world!"], "hello.txt", { type: "text/plain" })
const file2 = new File(["hello world again!"], "hello2.txt", { type: "text/plain" })
const upload = await pinata.upload.fileArray([file1, file2])
Returns
type PinResponse = {
IpfsHash: string;
PinSize: number;
Timestamp: string;
isDuplicate?: boolean;
};
Parameters
file
Accepts an array of File objects in accordance with the W3C File API.
const file1 = new File([blob1], "hello1.txt", { type: "text/plain" })
const file2 = new File([blob2], "hello2.txt", { type: "text/plain" })
const upload = await pinata.upload.fileArray([file1, file2])
Add optional metadata to file
const upload = await pinata.upload
.fileArray([file1, file2])
.addMetadata({
name: "pinnie.png",
keyValues: {
whimsey: 100
}
})
group (Optional)
Upload to a specific group by passing in the groupId
const upload = await pinata.upload
.fileArray([file1, file2])
.group("b07da1ff-efa4-49af-bdea-9d95d8881103")
key (Optional)
Upload a file using a secondary API key generated through keys.create()
const upload = await pinata.upload
.fileArray([file1, file2])
.key("GENERATED_API_JWT")
cidVersion (Optional)
Specificy CID version for upload
const upload = await pinata.upload
.fileArray([file1, file2])
.cidVersion(0)