props with uploadthing
Hi, I need help with uploadthing, I've been looking for several hours for a way to pass a props (category) and then add this category with the image url in my database, I'm using exactly the basic configuration of the nextjs app router doc.
Solution
if you set the input in your endpoint following the docs like this :
you can then pass the input in the component as
import { z } from "zod";
f(["imageEndpoint"])
.input(z.object({ foo: z.string() }))
.middleware(async ({ req, input }) => {
input;
// ^? { foo: string }
return {};
})
.onUploadComplete(async () => {});
you can then pass the input in the component as
<UploadButton<OurFileRouter>
endpoint="imageEndpoint"
onClientUploadComplete={(res) => {
// Do something with the response
console.log("Files: ", res);
alert("Upload Completed");
}}
input={{
foo: "your-string"
}}
/>