Lesson14: Error: readStream is not a readable stream or form data #4852
-
Issue description:At 21:45:57, I try the command: hh deploy --tags randomipfs,mocks I get this error: Error: readStream is not a readable stream or form data I get the error three times since the problem is within the for loop containing the readableStreamForFIle variable. My Code:This is my code for uploadToPinata.js: const pinataSDK = require("@pinata/sdk");
const path = require("path");
const fs = require("fs");
require("dotenv").config();
const pinataApiKey = process.env.PINATA_API_KEY;
const pinataApiSecret = process.env.PINATA_API_SECRET;
const pinata = new pinataSDK(pinataApiKey, pinataApiSecret);
async function storeImages(imagesFilePath) {
const fullImagesPath = path.resolve(imagesFilePath);
const files = fs.readdirSync(fullImagesPath).filter((file) => file.includes(".png"));
let responses = [];
for (fileIndex in files) {
const readableStreamForFile = fs.createReadStream(`${fullImagesPath}/${files[fileIndex]}`);
const options = {
pinataMetadata: {
name: files[fileIndex],
},
};
try {
const response = await pinata.pinFileToIPFS(
pinataApiKey,
pinataApiSecret,
readableStreamForFile.path,
options
);
responses.push(response);
} catch (e) {
console.log(e);
}
}
return { responses, files };
}
module.exports = { storeImages }; This is my code for 02-deploy-random-ipfs.js: const { network, ethers } = require("hardhat");
const { developmentChains, networkConfig } = require("../helper-hardhat-config");
const { storeImages } = require("../utils/uploadToPinata");
const { verify } = require("../utils/verify");
require("dotenv").config();
const imagesLocation = "./images/randomNft";
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();
const chainId = network.config.chainId;
let vrfCoordinatorV2Address, subscriptionId, tokenUris;
if (process.env.UPLOAD_TO_PINATA == "true") {
tokenUris = await handleTokenUris();
}
if (developmentChains.includes(network.name)) {
const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock");
vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address;
const tx = await vrfCoordinatorV2Mock.createSubscription();
const txReceipt = await tx.wait(1);
subscriptionId = txReceipt.events[0].args.subId;
} else {
vrfCoordinatorV2Address = networkConfig[chainId].vrfCoordinatorV2;
subscriptionId = networkConfig[chainId].subscriptionId;
}
log("-----------------------------------------");
await storeImages(imagesLocation);
// const args = [
// vrfCoordinatorV2Address,
// subscriptionId,
// networkConfig[chainId].gasLane,
// networkConfig[chainId].mintFee,
// networkConfig[chainId].callbackGasLimit,
// // Token URIs
// networkConfig[chainId].mintFee,
// ];
};
async function handleTokenUris() {
tokenUris = [];
return tokenUris;
}
module.exports.tags = ["all", "randomipfs", "main"]; PS:I tried debugging and trying to find the problem with the path. The value of readableStreamForFile.path is: "/home/mrpimp/linuxProjects/hardhat-nft/images/randomNft/pug.png" I've also tried using the clone of this repository and I got the same error. My best guess is that Pinata updated their library recently or that there is a problem with my computer which seems unlikely. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
@MrPimpDaddy69420 Add the forward slash at the end of images files folder path; -"./images/randomNft"
+"./images/randomNft/" |
Beta Was this translation helpful? Give feedback.
@MrPimpDaddy69420 Add the forward slash at the end of images files folder path;