How to use uploadthing server side?
Is this the correct way?
export const utapi = new UTApi(); // imported from uploadthing/server
// Extract image URLs and upload them to UploadThing
const uploadPromises = validatedData.map(async (item) => {
if (item.image) {
const response = await utapi.uploadFilesFromUrl(item.image);
if (response.error) {
throw new Error("Error uploading image");
}
item.image = response.data.url; // Replace with UploadThing URL
}
return item;
});export const utapi = new UTApi(); // imported from uploadthing/server
// Extract image URLs and upload them to UploadThing
const uploadPromises = validatedData.map(async (item) => {
if (item.image) {
const response = await utapi.uploadFilesFromUrl(item.image);
if (response.error) {
throw new Error("Error uploading image");
}
item.image = response.data.url; // Replace with UploadThing URL
}
return item;
});