How to pass arbitrary data from client to middleware in Uploadthing?

Just as the title said. I found this from stackoverflow, but I don't use the component. Here is my code, I am using sveltekit
<script>
const { startUpload } = createUploadThing("pdfUploader", { ... })
</script>

... omited for brevity ...
<Button
class="bg-blue-600 hover:bg-blue-700 {upload.status === "uploading" || file.file === null ? "" : "cursor-pointer"}"
disabled={upload.status === "uploading" || file.file === null}
onclick={async () => {
if (file.file !== null) {
await startUpload([file.file], { input: { foo: "bar" } });
}
}}
>
Start upload
</Button>
...
<script>
const { startUpload } = createUploadThing("pdfUploader", { ... })
</script>

... omited for brevity ...
<Button
class="bg-blue-600 hover:bg-blue-700 {upload.status === "uploading" || file.file === null ? "" : "cursor-pointer"}"
disabled={upload.status === "uploading" || file.file === null}
onclick={async () => {
if (file.file !== null) {
await startUpload([file.file], { input: { foo: "bar" } });
}
}}
>
Start upload
</Button>
...
// @lib/server/uploadthing.ts

... omited for brevity ...
const f = createUploadthing();

export const ourFileRouter = {
pdfUploader: f({
pdf: {
maxFileSize: "16MB",
maxFileCount: 1,
},
})
.middleware(async ({ req, files, input }) => {
console.log(input)
})
// @lib/server/uploadthing.ts

... omited for brevity ...
const f = createUploadthing();

export const ourFileRouter = {
pdfUploader: f({
pdf: {
maxFileSize: "16MB",
maxFileCount: 1,
},
})
.middleware(async ({ req, files, input }) => {
console.log(input)
})
With the above code, input is undefined.
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?