Im sending form details into the supabase server in applyform page
im submitting 4 form values which are:
name (string)
number (string)
title (string)
cv (file upload)
something i need to know before passing the file to the server function
const [name, setName] = useState("");
const [number, setNumber] = useState("");
const [title, setTitle] = useState("");
const [cv, setCV] = useState<File | null>(null);
setTimeout(async () => {
if (cv) {
const result = await applyJob(name, number, title, cv);
if (result.error) {
toast.error('Something went wrong!');
} else {
toast.success('Successfully Applied!');
applyjob function
"use server"
import { createClient } from "@/lib/supabase/server";
import { nanoid } from "nanoid";
export async function applyJob(
name: string,
number: string,
job: string,
cv: File
) {
const supabase = createClient();
// Upload the CV file to Supabase Storage
const fileExt = cv.name.split(".").pop();
const fileName = `${nanoid()}.${fileExt}`;
const filePath = `cv/${fileName}`;
const { data, error: uploadError } = await supabase.storage
.from("cv")
.upload(filePath, cv, {
cacheControl: "3600",
upsert: false,
});
if (uploadError) {
console.error("Error uploading CV:", uploadError);
return { error: uploadError.message };
}
// Get the public URL of the uploaded file
const publicURL = supabase.storage.from("cv").getPublicUrl(filePath).data.publicUrl;
// Insert the job application data into the JobApplications table
const { error: insertError } = await supabase
.from("JobApplications")
.insert([
{
name,
number,
job,
cv: publicURL,
},
]);
if (insertError) {
console.error("Error inserting job application:", insertError);
return { error: insertError.message };
}
return { success: true };
}
I’m expecting successfull submittsion of form and store data into supabase database