RDS Supabase Storage manages your files through three core concepts: buckets, folders, and files. Store media files such as images and videos in Storage to reduce the load on your database, and manage them from the RDS Supabase console or the RDS Supabase SDK.
Terms
Bucket: The top-level container for files. Create separate buckets when files require different security or access rules. For example, use one bucket for public images and another for private user profiles.
Folder: Organizes files inside a bucket, the same way folders work on your computer.
File: Any media file, such as an image or a video. Storing these large files in Storage reduces the load on your database. For security reasons, HTML files are served as plain text.
All bucket, folder, and file names must follow Alibaba Cloud OSS naming conventions. Avoid special characters.
Parameter settings
S3 backend configuration
RDS Supabase Storage includes a built-in Alibaba Cloud OSS backend, which is not visible to you. After you purchase RDS Supabase, you can use Storage directly. To use your own Alibaba Cloud OSS or another S3-compatible object storage service, configure the following parameters.
| Parameter | Description | Format and notes |
GLOBAL_S3_ENDPOINT | The endpoint of the OSS bucket |
|
GLOBAL_S3_BUCKET | The name of the OSS bucket |
|
REGION | The region of the OSS bucket |
|
TENANT_ID | The OSS directory name. You do not need to create it. |
|
AWS_ACCESS_KEY_ID | The AccessKey ID of the OSS bucket |
|
AWS_SECRET_ACCESS_KEY | The AccessKey secret of the OSS bucket |
|
AWS_SESSION_TOKEN | (Optional) The temporary access token of the OSS bucket. If you leave this parameter empty, authentication uses the AccessKey ID and AccessKey secret. |
|
USE_DEFAULT_S3_BACKEND | (Optional) Specifies whether to use the built-in OSS bucket |
|
When you use a custom OSS configuration (
USE_DEFAULT_S3_BACKEND=false), the backend releases the built-in Alibaba Cloud OSS bucket.When you use the built-in Alibaba Cloud OSS bucket (
Storage also provides the following general configuration parameter, which you can set separately:USE_DEFAULT_S3_BACKEND=true), the backend clears the custom OSS configuration.
| Parameter | Description | Format and notes |
FILE_SIZE_LIMIT | The size limit of a single file, in bytes |
|
S3 protocol configuration
Configure the S3 protocol to expose the S3 protocol endpoint of Storage. The endpoint is http(s)://<supabaseUrl>/storage/v1/s3. The region of the S3 protocol matches the region of the instance.
| Parameter | Description | Format and notes |
S3_PROTOCOL_ENABLED | Specifies whether to enable S3 protocol connections |
|
S3_PROTOCOL_ACCESS_KEY_ID | (Optional) The ACCESS_KEY_ID used to access the S3 protocol endpoint |
|
S3_PROTOCOL_ACCESS_KEY_SECRET | (Optional) The ACCESS_KEY_SECRET used to access the S3 protocol endpoint |
|
File storage
You can interact with Storage in either of the following ways:
RDS Supabase console: Provides a graphical interface for manual, visual file management. Choose the console to manage files manually.
RDS Supabase SDK: Provides programming interfaces to manage files automatically in an application, such as uploading user files or generating download links dynamically. Choose the SDK to integrate file operations into your application.
Manage files in the RDS Supabase console
Manage files in the RDS Supabase console
In the left sidebar of the RDS Supabase project console, select Storage to open the storage management page.
1. Create a bucket
When you use Storage for the first time, the page is empty. Create a bucket to store your files.
On the Storage page, click New bucket.
In the dialog box, enter a bucket name.
Decide whether to make the bucket public (Public bucket).
Public bucket: All files in the bucket are accessible by URL. Use it for public resources such as website logos and CSS files.
Private bucket (default): Files in the bucket require authorization to access. Use it for sensitive data such as user profiles and order information.
Click Create.
You cannot change a bucket name after you create the bucket. Bucket type defaults to Standard bucket, which is S3-compatible. You can also configure Restrict file size to limit the size of uploaded files and Restrict MIME types to allow only specific file types.
2. Upload and manage files
In the bucket list, click the bucket that you want to open.
Click Create folder to organize your file structure.
Click Upload files and select one or more files from your device.
After the upload finishes, the files appear in the list. Hover over a file and click the ... menu on the right to Download, Get URL, Move, or Delete it.
Use the RDS Supabase SDK
Use the RDS Supabase SDK
Use the official JavaScript client library (@supabase/supabase-js) to integrate file operations into your application. The following sections describe file operations in pseudocode.
1. Initialize the client
Before you start, make sure that the supabase-js library is installed. Initialize the client with the project URL and the ServiceKey.
import { createClient } from '@supabase/supabase-js';
// Get the URL and ServiceKey from your Supabase project settings
const supabaseUrl = 'YOUR_SUPABASE_URL';
const supabaseServiceKey = 'YOUR_SUPABASE_SERVICE_KEY';
const supabase = createClient(supabaseUrl, supabaseServiceKey);2. Create a bucket
Create a bucket named avatars.
// Use the JS library to create a bucket.
const { data, error } = await supabase.storage.createBucket('avatars');3. Upload a file
Upload a file to the avatars bucket.
const avatarFile = event.target.files[0];
const { data, error } = await supabase.storage
.from('avatars')
.upload('public/avatar1.png', avatarFile);4. Download a file
Download a specified file from the avatars bucket.
// Use the JS library to download a file. The complete sample code is as follows:
const { data, error } = await supabase.storage.from('avatars').download('public/avatar1.png');Security policy settings
RDS Storage Policies are storage access control policies based on the PostgreSQL row-level security (RLS) mechanism. They provide fine-grained control over storage object permissions at the database level.
You can set security policies in the RDS Supabase console in either of the following ways. The Policies page suits quick configuration and most scenarios. The SQL Editor is for complex scenarios or batch operations.
Set policies manually on the Policies page
Set policies manually on the Policies page
This method guides you through policy creation in a graphical interface. You do not need to write complex SQL.
In the left-side navigation pane of the RDS Supabase project console, choose Storage > Policies.
In the bucket list on the Policies page, click New Policy.
Select Get a policy from a template to use a preset storage template, or select Create a new policy from scratch for a fully custom configuration.
On the policy configuration page, fill in the following fields:
Policy name: A descriptive name for the policy, such as
Allow authenticated read access.Allowed operation: The operation to allow, such as
SELECT(download or list) orINSERT(upload).Target roles: The roles that the policy applies to, such as
authenticated(authenticated users).Policy definition: The conditions that must be met for reads, updates, or deletes. For example,
bucket_id = 'avatars'limits the policy to the bucket namedavatars.
Click Review to check the generated SQL statement. After you confirm it, click Save policy.
Configure policies in the SQL Editor
Configure policies in the SQL Editor
Run CREATE POLICY statements directly in the SQL Editor to create or modify policies.
Example 1: Allow public read access to a specified bucket
This policy allows anyone to read all files in the avatars bucket.
CREATE POLICY "Public read access for avatars"
ON storage.objects FOR SELECT
USING ( bucket_id = 'avatars' );Example 2: Allow authenticated users to access only their own files
This policy combination ensures that users can upload, view, update, and delete only the files in their personal folder (path: /*).
-- Allow authenticated users to upload files to their own folder
CREATE POLICY "Allow authenticated uploads in user folder"
ON storage.objects FOR INSERT
TO authenticated
WITH CHECK(bucket_id = 'avatars' AND auth.uid()::text = (storage.foldername(name))[1]);
-- Allow authenticated users to read files in their own folder
CREATE POLICY "Allow authenticated reads in user folder"
ON storage.objects FOR SELECT
TO authenticated
USING(bucket_id = 'avatars' AND auth.uid()::text = (storage.foldername(name))[1]);For more security policy settings, see the official Supabase storage security documentation.