you can now upload the img and vids and you get a url for it ill implement seeing that img and vid latter
This commit is contained in:
parent
f1675d0c6b
commit
5f53e923d0
3 changed files with 36 additions and 3 deletions
|
@ -1,8 +1,6 @@
|
|||
import { DefaultQuestions } from "$lib/config.js";
|
||||
|
||||
export let Wait = $state({
|
||||
v: false,
|
||||
});
|
||||
export let Wait = $state({ v: false });
|
||||
export let questions = $state({
|
||||
v: [
|
||||
{
|
||||
|
|
31
src/routes/kahootclone/create/logic/UpLoadFiles.js
Normal file
31
src/routes/kahootclone/create/logic/UpLoadFiles.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
import toast from "svelte-5-french-toast";
|
||||
import { supabase } from "$lib/supabase.js";
|
||||
|
||||
export async function UpLoadFiles(file) {
|
||||
if (!file) {
|
||||
toast.error("Please select a file to upload first.");
|
||||
return;
|
||||
}
|
||||
|
||||
const fileExt = file.name.split(".").pop();
|
||||
const fileName = `${Date.now()}.${fileExt}`;
|
||||
const filePath = `${fileName}`;
|
||||
|
||||
const uploadPromise = supabase.storage.from("useruploadedcontent").upload(filePath, file);
|
||||
|
||||
const result = await toast.promise(uploadPromise, {
|
||||
loading: "Uploading...",
|
||||
success: "Upload successful!",
|
||||
error: (error) => `Upload failed. ${error.message} Please try again.`,
|
||||
});
|
||||
|
||||
if (result.error) {
|
||||
console.error("Upload error:", result.error.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Retrieve public URL
|
||||
const { data: publicData } = supabase.storage.from("useruploadedcontent").getPublicUrl(filePath);
|
||||
|
||||
toast.success(publicData.publicUrl);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue