How to delete files in UploadThing?

I am using NextJS
    "@uploadthing/react": "^6.0.2",
    "next": "14.0.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "uploadthing": "^6.1.0"

I can't get the deleteFiles function to work for uploadthing
What I have tried,
created a uploadthing.js file in ~/server
"use server";

import { UTApi } from "uploadthing/server";

export const utapi = new UTApi();

I tried to call utapi.deleteFiles() but Webpack threw an error TypeError: _server_uploadthing__WEBPACK_IMPORTED_MODULE_3__.utapi.deleteFiles is not a function

I also tried declaring and exporting deleteFiles explicitly in server actions and calling it but it threw error like
Error deleting files: Error: inArray requires at least one value
I have referred the official docs but couldn't infer how to delete files
Solution
This seems to be the clunky way to fix it: https://github.com/pingdotgg/uploadthing/issues/213

I wanted to use Next.js because I thought I wouldn't have to make fetch calls to an internal API!
GitHub
hey, im getting "Missing UPLOADTHING_SECRET env variable." when trying to delete file. this is my code : export const deleteFiles = async (fileKey: string) => { await utapi.deleteFiles...
Was this page helpful?