MarvinKR
MarvinKR
Explore posts from servers
TTCTheo's Typesafe Cult
Created by MarvinKR on 7/11/2024 in #questions
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;
});
14 replies