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
bobo@bobos-Macbook-Air ipfsuploadbulk % node image.js
/Users/bobo/Downloads/ipfsuploadbulk/images.js:15
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();
ipfsArray.push({
path: images/${paddedHex}.png,
content: data.toString(ā€œbase64ā€)
})
res();
})
}))
}

Promise.all(promises).then( () => {
axios.post(ā€œhttps://deep-index.moralis.io/api/v2/ipfs/uploadFolderā€,
ipfsArray,
{
headers: {
ā€œEGLpjxRDz9WyGrI1gL18lalA0TxDS2pJKN7eF5gZfVGiXUdCM2k059r4g1tTaQ4Oā€: ā€˜ā€™,
ā€œContent-Typeā€: ā€œapplication/jsonā€,
ā€œacceptā€: ā€œapplication/jsonā€
}
}
).then( (res) => {
console.log(res.data);
})
.catch ( (error) => {
console.log(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
bobo@bobos-MacBook-Air 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’ +
ā€˜\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 …