Closed pat-mw closed 1 year ago
This may help add context.
This is my uploadthing router, following the docs down to a tee (but here you can see where the logs are)
import { createUploadthing, type FileRouter } from "uploadthing/next";
import { getServerAuthSession } from "@/server/auth";
const f = createUploadthing();
const auth = async (req: Request) => {
const session = await getServerAuthSession();
if (!session) return null;
if (!session.user) return null;
return session.user;
};
// FileRouter for your app, can contain multiple FileRoutes
export const ourFileRouter = {
// Define as many FileRoutes as you like, each with a unique routeSlug
imageUploader: f({ image: { maxFileSize: "2MB", maxFileCount: 10 } })
// Set permissions and file types for this FileRoute
.middleware(async ({ req }) => {
// This code runs on your server before upload
const user = await auth(req);
// If you throw, the user will not be able to upload
if (!user) throw new Error("Upload Unauthorized - Please log in...");
// Whatever is returned here is accessible in onUploadComplete as `metadata`
return { userId: user.id };
})
.onUploadComplete(({ metadata, file }) => {
// This code RUNS ON YOUR SERVER after upload
console.log("Upload complete for userId:", metadata.userId);
console.log("file url", file.url);
// !!! Whatever is returned here is sent to the clientside `onClientUploadComplete` callback
return { uploadedBy: metadata.userId, fileUrl: file.url};
}),
} satisfies FileRouter;
export type OurFileRouter = typeof ourFileRouter;
Also, I noticed that - whilst this error is not thrown on Dev, there is times when the uploadthing uploader gets stuck even after the upload is completed.
This only happens sometimes, and I don't really know the reason why -- whilst developing I have just refreshed the page and tried again and it usually works the second time.
Another bit of context (which i think is unrelated but I'm just being padantic): I'm using the SSR implementation with suspense as recommended in the uploadthing guide.
https://docs.uploadthing.com/getting-started/appdir#optional-uploadthing-ssr-plugin
The same error is happening to me, even the Vercel timeout errors are the same. I'm adding UT to the project today, so I might have missed something. I'll probably investigate more tomorrow!
"@uploadthing/react": "^6.0.0",
"uploadthing": "^6.0.1",
"next": "^14.0.3",
im facing this error too
latest release should resolve this. https://github.com/pingdotgg/uploadthing/releases
quick testing shows it works, thanks @markflorkowski -- I'll report back if the issue comes up again but seems to be fine now.
Super quick to respond, great work team (y)
Provide environment information
Describe the bug
In my dev environment, Uploadthing works exactly as expected. In my production environment, however, I'm having a bug, without much useful context:
Something went wrong. Please contact UploadThing and provide the following cause: SyntaxError: Unexpected token 'A', "An error o"... is not valid JSON
I'm reporting as the bug message told me to. It's 3am for me and I don't want to dig any deeper right now but I'll try and look into it properly in the next few days.
If anyone else has encountered this, in the meantime, please let me know :_
Link to reproduction
https://mrdn.vercel.app
To reproduce
Log in via Discord or Auth0, go to:
https://mrdn.vercel.app/dashboard/new-listing
Use file uploader.
See error
Additional information
Weirdly enough, It seems as though the files are indeed being uploaded (I can see them on the uploadthing dashboard) so I'm assuming the issue is something to do with the callbacks
Also, in case it helps.
It seems as though I'm getting a 504 from uploadthings api.
Then, my server-side logs (from Vercel) show the file succesfully uploaded.
Then, there is a 10second timeout.
๐จโ๐งโ๐ฆ Contributing
Code of Conduct