Installation and Setup
npm install @supabase/supabase-js
Install Supabase JS client
import { createClient } from '@supabase/supabase-js'
Import Supabase client
const supabase = createClient('SUPABASE_URL', 'SUPABASE_KEY')
Initialize Supabase client
File Upload
supabase.storage.from('bucket').upload('path/to/file.png', file)
Upload a file to a bucket
supabase.storage.from('bucket').upload('path/to/file.png', file, { upsert: true })
Upload file with upsert option
supabase.storage.from('bucket').upload('path/to/file.png', file, { contentType: 'image/png' })
Upload with content type
File Download
supabase.storage.from('bucket').download('path/to/file.png')
Download a file
const { data, error } = await supabase.storage.from('bucket').download('path/to/file.png')
Download with error handling
File Management
supabase.storage.from('bucket').list('folder/')
List files in a folder
supabase.storage.from('bucket').move('old/path.png', 'new/path.png')
Move a file
supabase.storage.from('bucket').copy('source/path.png', 'dest/path.png')
Copy a file
supabase.storage.from('bucket').remove(['path1.png', 'path2.png'])
Remove multiple files
URL Generation
supabase.storage.from('bucket').getPublicUrl('path/to/file.png')
Get public URL for a file
supabase.storage.from('bucket').createSignedUrl('path/to/file.png', 60)
Create signed URL that expires in 60 seconds
supabase.storage.from('bucket').createSignedUrls(['file1.png', 'file2.png'], 60)
Create multiple signed URLs
Bucket Management
supabase.storage.createBucket('bucket-name')
Create a new bucket
supabase.storage.getBucket('bucket-name')
Get bucket metadata
supabase.storage.listBuckets()
List all buckets
supabase.storage.updateBucket('bucket-name', { public: true })
Update bucket settings
supabase.storage.deleteBucket('bucket-name')
Delete a bucket
supabase.storage.emptyBucket('bucket-name')
Empty a bucket