1

How to upload a folder of images, by giving only path using npm's pinata sdk ? I only want to give folder's path. using javascript.

3 Answers 3

0

Ok, After a lot of R&D,found out that you cannot, upload folder of images using the pinata sdk(npm pack.). But you can use Moralis and IPFS public gateway.

0

You can use:

const IMAGES_LOCATION = "path/to/folder";
const imageFolderUploadResponse = await pinata.pinFromFS(IMAGES_LOCATION);
0

It's pretty simple using node.js (Javascript)

  1. First resolve the dir path
  2. Read by fs module in node.js
  3. Put the stuff in loop as per below code and then it will automatically pin your files to the Pinat
async function storeImages(imagesDirPath) {
  const fullImagesPath = path.resolve(imagesDirPath);
  const files = fs.readdirSync(fullImagesPath);
  let responses = [];
  console.log("Uploading to Pinata !!!");
  console.log("paths ", fs.createReadStream(fullImagesPath + "/" + files[0]));
  for (fileIndex in files) {
    const readableStreamForFile = fs.createReadStream(
      `${fullImagesPath}/${files[fileIndex]}`
    );
    try {
      const response = await pinata.pinFileToIPFS(readableStreamForFile);
      responses.push(response);
    } catch (error) {
      console.log(error);
    }
  }
  return { responses, files };
}

Your Answer

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

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