use this to get the dynamic number of total files in a folder
let totalFiles = fs.readdirSync(folder).length;
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
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
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 ā¦