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"
"@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();
"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
[BUG]: getting error on using utapi.deleteFiles · Issue #213 · ping...
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...
Jump to solution
5 Replies
Diversified
DiversifiedOP13mo ago
update: tried creating delete function in server/uploadthing.js but now i get the following error
[UT] Error: {
error: 'Error deleting files: Error: inArray requires at least one value'
}
[UT] Error: {
error: 'Error deleting files: Error: inArray requires at least one value'
}
I am passing the file keys as mentioned in https://discord.com/channels/966627436387266600/1169240516546789386/1181741963557478470 but still get the error
Diversified
DiversifiedOP13mo ago
No description
No description
Daniel J. Lewis
Daniel J. Lewis13mo ago
I'm having the same problem as your first post, except I'm still on Next.js 13.5.3. I also tried adding uploadthing/server to my serverComponentsExternalPackages in Next config. But that didn't fix it.
Solution
Daniel J. Lewis
Daniel J. Lewis13mo ago
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
[BUG]: getting error on using utapi.deleteFiles · Issue #213 · ping...
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...
Diversified
DiversifiedOP13mo ago
Thanks man, I hope they update the documentation and push a fix soon
Want results from more Discord servers?
Add your server