Closed kaspnilsson closed 9 months ago
My prod deployments work fine.
I think preview deployments on vercel require auth. Our callbacks wouldn't have that auth token, thus would fail.
I feel like we ran into this in the past, trying to remember the fix. cc @juliusmarminge
You can disable this feature in the vercel dashboard:
Obviously that comes with it's own security implications.
Or add this header in your app settings: https://vercel.com/docs/security/deployment-protection/methods-to-bypass-deployment-protection/protection-bypass-automation (if you have the feature on vercel)
Thanks, that is indeed the issue!
Even after disabling the header and also later adding the header, uploadthing keeps returning 200 with a servercallback message and a response of {"status":"still waiting"}
I started wondering, perhaps I did not add something in the code or perhaps because I did not add middleware authentication to the fileRouter
This is the core.ts: import { createUploadthing, type FileRouter } from "uploadthing/next";
const f = createUploadthing();
export const ourFileRouter = { imageUploader: f({ image: { maxFileSize: "4MB", minFileCount: 1, maxFileCount: 10 }, }).onUploadComplete(async ({ metadata, file }) => { return { fileUrl: file.url }; }), courseAttachment: f([ "text", "image", "video", "audio", "pdf", ]).onUploadComplete(() => {}), } satisfies FileRouter;
export type OurFileRouter = typeof ourFileRouter;
Please I need your help @kaspnilsson @markflorkowski
Hiii @kaspnilsson @markflorkowski
I fixed itttttttttt.. hahah
Middleware on the core.ts is necessary, even though it returns an empty object.
import { createUploadthing, type FileRouter } from "uploadthing/next";
const f = createUploadthing();
export const ourFileRouter = { imageUploader: f({ image: { maxFileSize: "4MB", maxFileCount: 10 } }) .middleware(async ({ req }) => { // This code runs on your server before upload console.log("Middleware for imageUploader"); return {}; // Return an empty object if no metadata is needed }) .onUploadComplete(async ({ metadata, file }) => { console.log("Upload completed:", file.url); return { fileUrl: file.url }; }),
courseAttachment: f(["text", "image", "video", "audio", "pdf"]) .middleware(async ({ req }) => { console.log("Middleware for courseAttachment"); return {}; }) .onUploadComplete(async ({ metadata, file }) => { console.log("Course attachment upload completed:", file); }), } satisfies FileRouter;
export type OurFileRouter = typeof ourFileRouter;
Also added this to next.config.mjs reactStrictMode: true, webpack: (config) => { config.externals = [...config.externals, { canvas: "canvas" }]; // required for uploadthing return config; },
Hopfully this helps someone, someday :)
Middleware on the core.ts is necessary, even though it returns an empty object
It shouldn't, interested to see a reproduction repo I can run that doesn't work without middleware
I actually do think that is intentional, but should probably be better documented.
middleware
should probably be called something like auth
, because we are expecting you to validate whether the upload should be allowed at that point or not. An empty middleware
function should feel bad, because it means you are not doing auth when you should.
Provide environment information
Describe the bug
I'm using the dropzone component thusly, within a form:
File router:
Files upload fine locally.
In production (using Vercel, on preview deployments), files upload fine, but the callback never executes on the server. Here's an example set of server logs:
The client is stuck in a loading state, with this message seemingly polling forever:
I do not think any of the scenarios in the docs pertain to my case, but maybe there's some complexity in dealing with Vercel preview deployments?
Link to reproduction
Follow instructions above -- issue is with deployment
To reproduce
Follow instructions above
Additional information
No response
๐จโ๐งโ๐ฆ Contributing
Code of Conduct