mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 21:59:16 +03:00
The RLS description appeared to have been copy-pasted from elsewhere, and did not reflect the RLS rule. Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>
64 lines
1.6 KiB
Plaintext
64 lines
1.6 KiB
Plaintext
---
|
|
id: 'storage-schema'
|
|
title: 'Storage Helper Functions'
|
|
description: 'Learn the storage schema'
|
|
subtitle: 'Learn the storage schema'
|
|
sidebar_label: 'Schema'
|
|
---
|
|
|
|
Supabase Storage provides SQL helper functions which you can use to write RLS policies.
|
|
|
|
### `storage.filename()`
|
|
|
|
Returns the name of a file. For example, if your file is stored in `public/subfolder/avatar.png` it would return: `'avatar.png'`
|
|
|
|
**Usage**
|
|
|
|
This example demonstrates how you would allow any user to download a file called `favicon.ico`:
|
|
|
|
```sql
|
|
create policy "Allow public downloads"
|
|
on storage.objects
|
|
for select
|
|
to public
|
|
using (
|
|
storage.filename(name) = 'favicon.ico'
|
|
);
|
|
```
|
|
|
|
### `storage.foldername()`
|
|
|
|
Returns an array path, with all of the subfolders that a file belongs to. For example, if your file is stored in `public/subfolder/avatar.png` it would return: `[ 'public', 'subfolder' ]`
|
|
|
|
**Usage**
|
|
|
|
This example demonstrates how you would allow authenticated users to upload files to a folder called `private`:
|
|
|
|
```sql
|
|
create policy "Allow authenticated uploads"
|
|
on storage.objects
|
|
for insert
|
|
to authenticated
|
|
with check (
|
|
(storage.foldername(name))[1] = 'private'
|
|
);
|
|
```
|
|
|
|
### `storage.extension()`
|
|
|
|
Returns the extension of a file. For example, if your file is stored in `public/subfolder/avatar.png` it would return: `'png'`
|
|
|
|
**Usage**
|
|
|
|
This example demonstrates how you would allow restrict uploads to only PNG files inside a bucket called `cats`:
|
|
|
|
```sql
|
|
create policy "Only allow PNG uploads"
|
|
on storage.objects
|
|
for insert
|
|
to authenticated
|
|
with check (
|
|
bucket_id = 'cats' and storage.extension(name) = 'png'
|
|
);
|
|
```
|