I'm interested in creating a JavaScript script that can automatically generate a folder on Pinata. Is such functionality available? My aim is to streamline the organization of JSON file uploads within this folder. Instead of saving the JSON files locally, I'd prefer to upload the data directly to Pinata. The data consists of event information in JSON format associated with tokenIDs.

1 Answer 1


It seems possible, here is the code provided by pinata docs.

const axios = require("axios");
const FormData = require("form-data");
const fs = require("fs");
const path = require("path");
const folderPath = "path/to/your/folder";

const pinFolderToIPFS = async () => {
  try {
    const formData = new FormData();
    const files = fs.readdirSync(folderPath);

    files.forEach(file => {
      const filePath = path.join(folderPath, file);
      formData.append("file", fs.createReadStream(filePath));

    const res = await axios.post(
        headers: {
          "Content-Type": `multipart/form-data; boundary=${formData._boundary}`,
          Authorization: `Bearer YOUR_PINATA_JWT`
  } catch (error) {


In this example, replace "path/to/your/folder" with the actual path to your folder, and YOUR_PINATA_JWT with your actual Pinata JWT token. This snippet iterates through each file in the specified folder, adds them to a FormData object, and then uploads the entire folder to Pinata via the pinFileToIPFS API endpoint.

  • Yes, the code pins the folder correctly, but my focus is on creating the folder name on Pinata. I'm not saving the folder locally; instead, I'm converting past Solidity contract events into JSON and then directly pushing them to Pinata. Commented May 1 at 17:05
  • You mean, you directly want to save your files into a pinata folder, one by one? Commented May 2 at 4:40
  • I want to make the folder name inside pinata using JS. Commented May 2 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.