Module 4
Topic 4

Storage

Managing file uploads, downloads, and media storage with Supabase Storage buckets.

Supabase Storage Overview supabase_flutter package
Supabase Storage Overview

Supabase Storage provides a scalable file storage solution for your Flutter apps. It's built on top of Amazon S3 and offers:

  • Public & Private Buckets – Control who can access your files
  • Image Optimization – Automatic resizing and optimization
  • CDN Delivery – Fast global content delivery
  • File Management – Upload, download, delete, and list files
  • Security – Row Level Security policies for storage
🌐
Public Buckets
Anyone can read files. Good for profile pictures, public assets
🔒
Private Buckets
Only authenticated users with proper permissions can access

✅ Storage Use Cases

  • Profile Pictures – User avatars uploaded to a public bucket
  • Post Images – Images for posts or articles
  • Video Uploads – User-generated video content
  • Documents – PDFs, spreadsheets, and other documents
  • Chat Media – Images and files in chat messages
Setting Up Storage

To use storage in your Flutter app, you need to create a bucket and set up the proper policies.

Uploading Files

Uploading files to Supabase Storage is done through the storage API.

Downloading Files

There are two ways to access files from Supabase Storage: public URLs and signed URLs.

🔑 Public vs Signed URLs

  • Public URLs – Anyone can access. Use for public buckets (avatars, logos, etc.)
  • Signed URLs – Temporary access. Use for private buckets (user documents, etc.)
  • Signed URLs expire – Default is 60 seconds, can be customized
Listing and Managing Files

You can list, move, copy, and delete files in Supabase Storage.

Complete Example: Image Gallery App

Here's a complete image gallery app using Supabase Storage.

Step-by-Step Explanation
1.
Create a bucket – Use the SQL Editor or Supabase Dashboard to create public or private buckets.
2.
Set up policies – Create RLS policies to control who can upload, read, and delete files.
3.
Upload files – Use storage.from(bucket).uploadBinary() to upload files.
4.
Get URLs – Use getPublicUrl() for public buckets or createSignedUrl() for private buckets.
5.
Display images – Use CachedNetworkImage for efficient image loading with caching.
Common Mistakes
❌ Mistake 1: Not setting up storage policies

Without proper policies, users won't be able to upload or access files, even if the bucket is public.

✅ Correct: Always set up RLS policies

Create policies for INSERT, SELECT, DELETE operations on the storage.objects table.

❌ Mistake 2: Using public URLs for private buckets

Public URLs only work for public buckets. For private buckets, you need signed URLs.

✅ Correct: Use signed URLs for private buckets

Use createSignedUrl() to get temporary access to private files.

❌ Mistake 3: Not handling upload errors

Uploads can fail for many reasons (network issues, file size limits, etc.). Always handle errors gracefully.

✅ Correct: Always handle upload errors

Use try-catch blocks and show user-friendly error messages when uploads fail.

🎯 Key Takeaway

Supabase Storage provides scalable file storage with public and private buckets. Use public URLs for public assets and signed URLs for private files. Always set up RLS policies for security and use CachedNetworkImage for efficient image display. Storage makes media management simple and secure.