Server example of UTApi.uploadFiles with setting a customId?

I can't see to find any examples or docs around this;
const uploadthingFile = new File([file], key, {
type: file.type,
})
const response = await uploadthingApi.uploadFiles(uploadthingFile)
const uploadthingFile = new File([file], key, {
type: file.type,
})
const response = await uploadthingApi.uploadFiles(uploadthingFile)
How can you set a customId on upload from the server?
4 Replies
webdevkaleem
webdevkaleem2mo ago
the options object passed has customId property which you can add thus making your code to be
const uploadthingFile = new File([file], key, {
type: file.type,
customId: "my-custom-id"
})
const response = await uploadthingApi.uploadFiles(uploadthingFile)
const uploadthingFile = new File([file], key, {
type: file.type,
customId: "my-custom-id"
})
const response = await uploadthingApi.uploadFiles(uploadthingFile)
nickplx
nickplxOP2mo ago
How do you line up the types?
Object literal may only specify known properties, and 'customId' does not exist in type 'FilePropertyBag'
I ignore this error and on the upload the response still shows customId: null
webdevkaleem
webdevkaleem2mo ago
can you log to see if the customId is null or not when you're uploading and see if you're importing correctly from the server
import { UTApi, UTFile } from "uploadthing/server";
import { UTApi, UTFile } from "uploadthing/server";
I don't know much about the types error i think this might be the case pass your uploadthingFile inside an array when uploading it
uploadthingApi.uploadFiles([uploadthingFile])
uploadthingApi.uploadFiles([uploadthingFile])

Did you find this page helpful?