apps/docs/content/guides/storage/quickstart.mdx
This guide shows the basic functionality of Supabase Storage. Find a full example application on GitHub.
Supabase Storage consists of Files, Folders, and Buckets.
Files can be any sort of media file. This includes images, GIFs, and videos. It is best practice to store files outside of your database because of their sizes. For security, HTML files are returned as plain text.
Folders are a way to organize your files (just like on your computer). There is no right or wrong way to organize your files. You can store them in whichever folder structure suits your project.
Buckets are distinct containers for files and folders. You can think of them like "super folders". Generally you would create distinct buckets for different Security and Access Rules. For example, you might keep all video files in a "video" bucket, and profile pictures in an "avatar" bucket.
<Admonition type="note">File, Folder, and Bucket names must follow AWS object key naming guidelines and avoid use of any other characters.
</Admonition>You can create a bucket using the Supabase Dashboard. Since the storage is interoperable with your Postgres database, you can also use SQL or our client libraries. Here we create a bucket called "avatars":
<Tabs scrollable size="small" type="underlined" defaultActiveId="dashboard" queryGroup="language"
<TabPanel id="dashboard" label="Dashboard">
-- Use Postgres to create a bucket.
insert into storage.buckets
(id, name)
values
('avatars', 'avatars');
// Use the JS library to create a bucket.
const { data, error } = await supabase.storage.createBucket('avatars')
void main() async {
final supabase = SupabaseClient('supabaseUrl', 'supabaseKey');
final storageResponse = await supabase
.storage
.createBucket('avatars');
}
try await supabase.storage.createBucket("avatars")
response = supabase.storage.create_bucket('avatars')
You can upload a file from the Dashboard, or within a browser using our JS libraries.
<Tabs scrollable size="small" type="underlined" defaultActiveId="dashboard" queryGroup="language"
<TabPanel id="dashboard" label="Dashboard">
const avatarFile = event.target.files[0]
const { data, error } = await supabase.storage
.from('avatars')
.upload('public/avatar1.png', avatarFile)
void main() async {
final supabase = SupabaseClient('supabaseUrl', 'supabaseKey');
// Create file `example.txt` and upload it in `public` bucket
final file = File('example.txt');
file.writeAsStringSync('File content');
final storageResponse = await supabase
.storage
.from('public')
.upload('example.txt', file);
}
You can download a file from the Dashboard, or within a browser using our JS libraries.
<Tabs scrollable size="small" type="underlined" defaultActiveId="dashboard" queryGroup="language"
<TabPanel id="dashboard" label="Dashboard">
// Use the JS library to download a file.
const { data, error } = await supabase.storage.from('avatars').download('public/avatar1.png')
void main() async {
final supabase = SupabaseClient('supabaseUrl', 'supabaseKey');
final storageResponse = await supabase
.storage
.from('public')
.download('example.txt');
}
let response = try await supabase.storage.from("avatars").download(path: "public/avatar1.png")
response = supabase.storage.from_('avatars').download('public/avatar1.png')
To restrict access to your files you can use either the Dashboard or SQL.
<Tabs scrollable size="small" type="underlined" defaultActiveId="dashboard" queryGroup="database-method"
<TabPanel id="dashboard" label="Dashboard">
OBJECTS table to add policies for Files. You can also create policies for Buckets.-- Use SQL to create a policy.
create policy "Public Access"
on storage.objects for select
using ( bucket_id = 'public' );