Skip to main content

Features

  • File upload and download
  • Public and private buckets
  • File transformations
  • Image resizing
  • Access control
  • CDN integration

Setup

1. Enable Storage in Supabase

  1. Go to your Supabase project dashboard
  2. Navigate to Storage in the sidebar
  3. Create a new bucket or use the default public bucket

2. Configure Environment Variables

Add these variables to your .env file:

3. Install Dependencies

Usage

Initialize Supabase Client

File Upload

File Download

Get Public URL

Delete File

Bucket Management

Create Bucket

List Files

Security

Row Level Security (RLS)

Enable RLS on your storage buckets to control access:

Access Control

  1. Public Buckets
    • Files are publicly accessible
    • Use for public assets like images
    • No authentication required
  2. Private Buckets
    • Files require authentication
    • Use for user uploads
    • Implement RLS policies

Best Practices

  1. File Organization
    • Use meaningful folder structures
    • Implement file naming conventions
    • Clean up unused files
  2. Security
    • Enable RLS on all buckets
    • Validate file types
    • Set file size limits
    • Use private buckets for sensitive data
  3. Performance
    • Use CDN for public files
    • Implement caching strategies
    • Optimize file sizes
  4. Error Handling
    • Implement proper error handling
    • Add retry logic for uploads
    • Validate file operations

Common Use Cases

  1. User Profile Images
  2. Document Storage
  3. Public Assets

Troubleshooting

Common Issues

  1. Upload Failures
    • Check file size limits
    • Verify bucket permissions
    • Ensure proper authentication
  2. Access Denied
    • Verify RLS policies
    • Check user authentication
    • Confirm bucket settings
  3. Performance Issues
    • Use CDN for public files
    • Implement caching
    • Optimize file sizes

Additional Resources