Skip to content

Commit

Permalink
up router
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusmarminge committed Jan 29, 2024
1 parent 6bcb2fa commit facdb28
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions examples/minimal-expo/app/uploadthing+api.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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,
Expand Down

0 comments on commit facdb28

Please sign in to comment.