I am getting the following error. I have reduced the file sizes and am only referencing 3 images in the folder for now. The images are .jpeg format. I changed the file extensions in the script to match. I am using the 64 hex naming convention.
Also, I am seeing that the .substr in i.toString(16)).substr("-64") is depricated but not sure what I should use instead.
Davids-MacBook-Air-3:ipfs-bulk-upload David$ node images.js
/Users/David/Desktop/ipfs-bulk-upload/images.js:15
content: data.toString(“base64”)
^TypeError: Cannot read property ‘toString’ of undefined
at ReadFileContext.fs.readFile [as callback] (/Users/David/Desktop/ipfs-bulk-upload/images.js:15:31)
at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:441:13)
et fs = require("fs");
let axios = require("axios");
let ipfsArray = [];
let promises = [];
for (let i = 0; i < 100; i++) {
let paddedHex = ("0000000000000000000000000000000000000000000000000000000000000000" + i.toString(16)).substr("-64");
promises.push(new Promise((res, rej) => {
fs.readFile(`${__dirname}/export/${paddedHex}.jpeg`, (err, data) => {
if (err) rej();
ipfsArray.push({
path: `images/${paddedHex}.jpeg`,
content: data.toString("base64")
})
res();
})
}))
}
Promise.all(promises).then(() => {
axios.post("https://deep-index.moralis.io/api/v2/ipfs/uploadFolder",
ipfsArray,
{
headers: {
"X-API-KEY": 'w3gMLAPhijPzdQZE8Y3s8USUSAKzPBdy0yhcavZE7AtfCzWg241kosqB79TP0Q5B',
"Content-Type": "application/json",
"accept": "application/json"
}
}
).then((res) => {
console.log(res.data);
})
.catch((error) => {
console.log(error)
})
})