CodeWrangler_
CodeWrangler_
TTCTheo's Typesafe Cult
Created by CodeWrangler_ on 5/7/2025 in #questions
NextJS customId support in /api/uploadthing route
on the client side of my app i have a handler function to upload to uploadthing using the uploadthing route:
// Upload video to UploadThing
const handleSubmit = async () => {
const uniqueFileName = `${formData?.form_id}-${
formData?.created_at
}-${Date.now()}`;

if (!recordedVideo) {
toast.error("No video to upload");
return;
}

try {
const response = await fetch(recordedVideo);
const blob = await response.blob();
const file = new File([blob], `${uniqueFileName}.webm`, {
type: VIDEO_FORMAT,
});

const uploadResult = await startUpload([file], {
customId: uniqueFileName,
});
if (!uploadResult) {
throw new Error("Upload failed");
}

const [res] = uploadResult;
if (res) {
toast.success("Thank you for your testimonial!");
console.log("Uploaded video URL:", res.url);
}
} catch (error) {
console.error("Error uploading video:", error);
toast.error("Failed to upload video. Please try again.");
}
};
// Upload video to UploadThing
const handleSubmit = async () => {
const uniqueFileName = `${formData?.form_id}-${
formData?.created_at
}-${Date.now()}`;

if (!recordedVideo) {
toast.error("No video to upload");
return;
}

try {
const response = await fetch(recordedVideo);
const blob = await response.blob();
const file = new File([blob], `${uniqueFileName}.webm`, {
type: VIDEO_FORMAT,
});

const uploadResult = await startUpload([file], {
customId: uniqueFileName,
});
if (!uploadResult) {
throw new Error("Upload failed");
}

const [res] = uploadResult;
if (res) {
toast.success("Thank you for your testimonial!");
console.log("Uploaded video URL:", res.url);
}
} catch (error) {
console.error("Error uploading video:", error);
toast.error("Failed to upload video. Please try again.");
}
};
3 replies