Supabase Storage provides a simple and secure way to store and serve files in your application. It is built on top of PostgreSQL and provides a RESTful API for file operations.
// Get public URL for a filefunction getPublicUrl(path: string, bucket: string = 'public') { const { data } = supabase.storage .from(bucket) .getPublicUrl(path) return data.publicUrl}
Enable RLS on your storage buckets to control access:
Copy
-- Example RLS policy for authenticated usersCREATE POLICY "Authenticated users can upload files"ON storage.objectsFOR INSERTTO authenticatedWITH CHECK (bucket_id = 'public');-- Example RLS policy for public accessCREATE POLICY "Public files are accessible to everyone"ON storage.objectsFOR SELECTTO publicUSING (bucket_id = 'public');