IPFS-BULK-UPLOAD project 'toString' error

use this to get the dynamic number of total files in a folder

let totalFiles = fs.readdirSync(folder).length;

Hey, I’ve been troubleshooting this string issue since yesterday with no success.
I have checked the names of files and are paddedhex 64 digit forms, I have also made sure the amount of them was between 5-10mb, even played with taking some out and making it less than 5mb. I am using png’s.
I use the same folder structures. The substr(“64”) is deprecated
Aside from this deprecation, I have the same code as Filip. Of course I have my api key in there.
Could my server online be the issue?

Below is what I type and it’s response.

Node.js v17.4.0
[email protected] ipfsuploadbulk % node image.js
content: data.toString(“base64”)

TypeError: cannot read properties of undefined (reading ‘toString’)
at ReadFileContext.callback (/Users/bobo/Downloads/ipfsuploadbulk/images.js:15:31

this is my code
let 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}.png, (err, data) => {
if(err) rej();
path: images/${paddedHex}.png,
content: data.toString(“base64”)

Promise.all(promises).then( () => {
headers: {
“EGLpjxRDz9WyGrI1gL18lalA0TxDS2pJKN7eF5gZfVGiXUdCM2k059r4g1tTaQ4O”: ‘’,
“Content-Type”: “application/json”,
“accept”: “application/json”
).then( (res) => {
.catch ( (error) => {

any help would be great. thank you

can you try with 1MB for total folder size?
after that you’ll have to check if files are in the expected folder (fs.readFile(${__dirname}/export/${paddedHex}.png, ()

yes. thank you.
Not sure what is up… trying many things on other posts and changing directories to get the correct one, even tho i know the .png’s are where they need to be…
I got this error, something new after playing
[email protected] ipfsuploadbulk % node images.js
Debugger attached.
[Error: ENOENT: no such file or directory, open ‘/export/0000000000000000000000000000000000000000000000000000000000000000.png’] {
errno: -2,
code: ‘ENOENT’,
syscall: ‘open’,
path: ‘/export/0000000000000000000000000000000000000000000000000000000000000000.png’
[Error: ENOENT: no such file or directory, open ‘/export/0000000000000000000000000000000000000000000000000000000000000001.png’] {
errno: -2,
code: ‘ENOENT’,
syscall: ‘open’,
path: ‘/export/0000000000000000000000000000000000000000000000000000000000000001.png’
[Error: ENOENT: no such file or directory, open ‘/export/0000000000000000000000000000000000000000000000000000000000000002.png’] {
errno: -2,
code: ‘ENOENT’,
syscall: ‘open’,
path: ‘/export/0000000000000000000000000000000000000000000000000000000000000002.png’

From that error it looks like it tries to search in an absolute path starting with /export

1 Like

Actually figured out that it had to do with the amount of zeros in the filename… I counted them many times, to all total 64, but I guess I don’t know how to count that high lmao. I just copied the zeros from inside the code to the images, with the corresponding 1, 2, 3’s after…
wow. I definitely learned a lot troubleshooting this script tho. Thanks again all comments above

1 Like

cryptokid, do you know if there is a workaround to the filesize of the folder? I mean this code is great but even have a folder that is 7mb will not work. Seems I can only upload about 10 files at a time. I did an upgrade with moralis and still cannot seem to do an actual BULK upload. Any insight would be great. Thanks again

for now I don’t know of a solution with Moralis, you could try to upload all the files to an IPFS folder with another IPFS provider

tried every solution on here… the i = 0 one worked to file one file but overall nothing… extremely frustrated with this

most of the times it tries to access a path that doesn’t exist

data: { message: ‘Invalid files or path are duplicated’ }

i’m getting this error now … before it was just the toString error
any ideas ? full code below
headers: [Object],
transformRequest: [Array],
transformResponse: [Array],
timeout: 0,
adapter: [Function: httpAdapter],
xsrfCookieName: ‘XSRF-TOKEN’,
xsrfHeaderName: ‘X-XSRF-TOKEN’,
maxContentLength: -1,
maxBodyLength: -1,
validateStatus: [Function: validateStatus]
request: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: null,
_hasBody: true,
_trailer: ‘’,
finished: true,
_headerSent: true,
socket: [TLSSocket],
connection: [TLSSocket],
_header: ‘POST /api/v2/ipfs/uploadFolder HTTP/1.1\r\n’ +
‘Accept: application/json\r\n’ +
‘Content-Type: application/json\r\n’ +
‘X-API-KEY: C1HjXxEKVTOJMLaqiB69wCJArzOgq20MZ1LASAY9giVTGDt3nn9KwRIixPvMVljs\r\n’ +
‘User-Agent: axios/0.20.0\r\n’ +
‘Content-Length: 4254937\r\n’ +
‘Host: deep-index.moralis.io\r\n’ +
‘Connection: close\r\n’ +
_keepAliveTimeout: 0,
_onPendingData: [Function: noopPendingOutput],
agent: [Agent],
socketPath: undefined,
method: ‘POST’,
insecureHTTPParser: undefined,
path: ‘/api/v2/ipfs/uploadFolder’,
_ended: true,
res: [IncomingMessage],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: ‘deep-index.moralis.io’,
protocol: ‘https:’,
_redirectable: [Writable],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
data: { message: ‘Invalid files or path are duplicated’ }
isAxiosError: true,
toJSON: [Function: toJSON]

it looks like this is a new error that we have, we will have to fix it, this looks like is not from your code

: (
any other way to upload nfts in bulk ?

you can upload them separately with pinata if you want
I don’t know exactly how fast we will fix this ‘Invalid files or path are duplicated’ error

ill check it out thanks…

that error with Invalid files or path are duplicated should be fixed now

wow lets sees if this will work

its working but only downloading one file … maybe the amount of zeros is wrong … its 64 zeros and then 1 right ?

I think that in total it has to be 64 characters, as in 63 zeros and 1

ok let me fix it and come back thanks though regardless… this is the fastest i received a reply for an issue ever …