From 20fe2f9fb18a670014c5c0aca31e182076919e5b Mon Sep 17 00:00:00 2001 From: juliusmarminge Date: Mon, 29 Jan 2024 10:00:32 +0100 Subject: [PATCH] up router --- examples/minimal-expo/app/uploadthing+api.ts | 41 ++++++++++---------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/examples/minimal-expo/app/uploadthing+api.ts b/examples/minimal-expo/app/uploadthing+api.ts index 452b431549..f093472614 100644 --- a/examples/minimal-expo/app/uploadthing+api.ts +++ b/examples/minimal-expo/app/uploadthing+api.ts @@ -1,9 +1,24 @@ import { createRouteHandler, createUploadthing } from "uploadthing/server"; import type { FileRouter } from "uploadthing/server"; -const f = createUploadthing(); +const f = createUploadthing({ + /** + * Log out more information about the error, but don't return it to the client + * @see https://docs.uploadthing.com/errors#error-formatting + */ + errorFormatter: (err) => { + console.log("Error uploading file", err.message); + console.log(" - Above error caused by:", err.cause); -const uploadRouter = { + return { message: err.message }; + }, +}); + +/** + * This is your Uploadthing file router. For more information: + * @see https://docs.uploadthing.com/api-reference/server#file-routes + */ +export const uploadRouter = { videoAndImage: f({ image: { maxFileSize: "4MB", @@ -12,26 +27,12 @@ const uploadRouter = { video: { maxFileSize: "16MB", }, - }) - .middleware(({ req }) => { - // Check some condition based on the incoming requrest - req; - //^? - // if (!req.headers["x-some-header"]) { - // throw new Error("x-some-header is required"); - // } - - // Return some metadata to be stored with the file - return { foo: "bar" as const }; - }) - .onUploadComplete(({ file, metadata }) => { - metadata; - // ^? - console.log("upload completed", file); - }), + }).onUploadComplete((data) => { + console.log("upload completed", data); + }), } satisfies FileRouter; -export type UploadRouter = typeof uploadRouter; +export type OurFileRouter = typeof uploadRouter; export const { GET, POST } = createRouteHandler({ router: uploadRouter,