Upload a single file stream to Pinata
HTML uploads are currently only available on paid plans with granted access. If you are on a paid plan and wish to upload HTML please send a request through our support chat or send an email to
[email protected]
Usage
import { PinataSDK } from "pinata-web3";
import fs from "fs"
const pinata = new PinataSDK({
pinataJwt: process.env.PINATA_JWT!,
pinataGateway: "example-gateway.mypinata.cloud",
});
const stream = fs.createReadStream("path/to/file")
const upload = await pinata.upload.stream(stream)
Returns
type PinResponse = {
IpfsHash: string;
PinSize: number;
Timestamp: string;
isDuplicate?: boolean;
};
Parameters
stream
- Type:
NodeJS.ReadableStream
Accepts a local file as a ReadableStream
const stream = fs.createReadStream("path/to/file")
const upload = await pinata.upload.stream(stream)
Add optional metadata to file
const upload = await pinata.upload
.stream(stream)
.addMetadata({
name: "pinnie.png",
keyValues: {
whimsey: 100
}
})
group (Optional)
Upload to a specific group by passing in the groupId
const upload = await pinata.upload
.stream(stream)
.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
.stream(stream)
.key("GENERATED_API_JWT")
cidVersion (Optional)
Specificy CID version for upload
const upload = await pinata.upload
.stream(stream)
.cidVersion(0)