Upload Media File
BuilderKit allows you to store media files in Supabase Storage. Check out the Setup for the configuration required to use it.
The code for uploading a file in supabase storage is implemented in the following file /src/utils/supabase/storage.ts
.
Since Vercel does not allow data transfer of more than 4.5 MB, we are implementing this code on the client side securely. This way, you can upload files as large as you want (based on the limit set in Supabase) directly from the frontend.
How to use?
-
To upload a file, call the upload function and pass the file you want to upload to the storage/cloud:
import { upload } from "@/utils/supabase/storage"; await upload(file);
-
To create a Signed Url of the uploaded file call the getSignedUrl function and pass the filepath:
import { getSignedUrl } from "@/utils/supabase/storage"; await getSignedUrl(filepath);
-
To get a Public Url of the uploaded file call the getPublicUrl function and pass the filepath:
import { getPublicUrl } from "@/utils/supabase/storage"; await getPublicUrl(filepath);