Upload file from nodejs local path

Im just trying to write a simple node js script that will upload a local file to uploadthing but get the following error:
UploadThingError: Invalid request input

Here is the node JS script:

async function uploadFile() {
  const utapi = new UTApi();

  const buffer = fs.readFileSync(`./dist/${filename}`);
  const blob = new Blob([buffer]);

  try {
    await utapi.deleteFiles(pkgJson.name, { keyType: 'customId' });
  } catch (error) {
    console.log('error deleting files');
    console.error(error);
  }

  try {
    const response = await utapi.uploadFiles({
      ...blob,
      name: filename,
      customId: pkgJson.name,
    });
    console.log(JSON.stringify(response, null, 2));
  } catch (error) {
    console.log('error uploading files');
    console.error(error);
  }
}

Plz help guide me through this thanks 📿
Was this page helpful?