Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
Strange, inconsistent path type not defined error for NodeJS file upload to IPFS

So I have just come across a very strange bug. I am trying to bulk upload images to IPFS using a private API key. The images are coming from my project directory and when I run the code, it works but only for a couple images. The rest of the images get the same error shown, that I am not using a string when it wants a string. The strangest thing is that when I re-run the code, I get anywhere from 2 images working to 5 working, the rest failing. And in almost every test, image 8 is the first one being uploaded. This is so strange to me, I can't figure out if my code is wrong (but then my errors would be consistent, right?), or maybe my API key is broken somehow, or maybe it's just doing everything too fast for the server to keep up. I am lost, any ideas?

FILE I AM RUNNING:

import FormData from 'form-data';
import fetch from 'node-fetch';
import path from 'path';
const basePath = process.cwd();
import fs from 'fs';

fs.readdirSync(`${basePath}/build/images`).forEach(file => {
    const formData = new FormData();
    const fileStream = fs.createReadStream(`${basePath}/build/images/${file}`);
    formData.append('file', fileStream);


    let url = 'https://api.nftport.xyz/v0/files';
    
    let options = {
      method: 'POST',
      headers: {
        Authorization: (private),
      },
      body: formData
    };
    
    fetch(url, options)
      .then(res => res.json())
      .then(json => {
          const fileName = path.parse(json.file_name).name;
          let rawdata = fs.readFileSync(`${basePath}/build/json/${fileName}.json`);
          let metaData = JSON.parse(rawdata);

          metaData.file_url = json.ipfs_url;

          fs.writeFileSync(`${basePath}/build/json/${fileName}.json`, JSON.stringify(metaData, null, 2));

          console.log(`${json.file_name} uploaded and ${fileName}.json updated!`);
      })
      .catch(err => console.error('error:' + err));

})

OUTPUT:

DeprecationWarning: form-data doesn't follow the spec and requires special treatment. Use alternative package
(Use `node --trace-deprecation ...` to show where the warning was created)
error:TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
error:TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
error:TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
8.png uploaded and 8.json updated!
10.png uploaded and 10.json updated!
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!