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);
}
}
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 📿
2 Replies
Imoxto
ImoxtoOP•10mo ago
doesnt work with local file urls either :thinkies:
Imoxto
ImoxtoOP•10mo ago
tried this:
const response = await utapi.uploadFilesFromUrl({
url: url.pathToFileURL(`./dist/${filename}`).toString(),
customId: pkgJson.name,
});
const response = await utapi.uploadFilesFromUrl({
url: url.pathToFileURL(`./dist/${filename}`).toString(),
customId: pkgJson.name,
});
but got error:
No description
Want results from more Discord servers?
Add your server