UT | Express.js | onUploadComplete doesn't trigger at all

Hi all, this is first time i am trying uploadthing. in my express server i configured it like this:
const uploadthing = createUploadthing({
errorFormatter: (err) => {
return { message: "Something went wrong, please try again!" };
},
});

const appRoutes = new Router();

export const uploadthingUploader = {
imageUploader: uploadthing({
image: {
maxFileSize: "512KB",
maxFileCount: 1,
minFileCount: 1,
acl: "public-read",
},
})
.middleware(async ({ req, res, event }) => {
let token = req.cookies?.token;
if (!token) {
token = req.headers?.token;
}
if (!token) {
throw new UploadThingError("unauthorized!");
}
const user = genericUtils.decodeJWT(token);
if (!user)
throw new UploadThingError(
"You must be logged in to upload a profile picture"
);
return { userId: user?.userId };
})
.onUploadComplete(async ({ metadata }) => {
console.log(`bro please work ❌`);
console.log("Uploaded 🔥 by user", metadata);
}),
};

appRoutes.use(
"/uploadthing",
createRouteHandler({
router: uploadthingUploader,
config: {
logLevel: "Error",
},
})
);
const uploadthing = createUploadthing({
errorFormatter: (err) => {
return { message: "Something went wrong, please try again!" };
},
});

const appRoutes = new Router();

export const uploadthingUploader = {
imageUploader: uploadthing({
image: {
maxFileSize: "512KB",
maxFileCount: 1,
minFileCount: 1,
acl: "public-read",
},
})
.middleware(async ({ req, res, event }) => {
let token = req.cookies?.token;
if (!token) {
token = req.headers?.token;
}
if (!token) {
throw new UploadThingError("unauthorized!");
}
const user = genericUtils.decodeJWT(token);
if (!user)
throw new UploadThingError(
"You must be logged in to upload a profile picture"
);
return { userId: user?.userId };
})
.onUploadComplete(async ({ metadata }) => {
console.log(`bro please work ❌`);
console.log("Uploaded 🔥 by user", metadata);
}),
};

appRoutes.use(
"/uploadthing",
createRouteHandler({
router: uploadthingUploader,
config: {
logLevel: "Error",
},
})
);
problem is onUploadComplete doesn't trigger at all although my images are uploaded successfully. also middleware checks pass. i need to save the uploaded image url to DB. thats why i need onUploadComplete . Thanks.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server