File Storage
Scenarios
This section describes the file storage (Storage) feature of Huawei Cloud RDS Supabase, including console configuration, file management, SDK operations, and security policy configuration.
File storage integrates with Huawei Cloud Object Storage Service (OBS) at the underlying layer, providing out-of-the-box object storage compatible with the S3 standard. You do not need to purchase third-party storage separately, build your own file storage servers, or manage the underlying infrastructure. OBS uses pay-per-use billing and is billed based on factors such as the storage capacity, number of requests, and public network traffic. For details, see Huawei Cloud OBS Pricing Details.
RDS Supabase provides a one-stop managed service. OBS buckets handle file uploads, downloads, and previews, while flexible and secure APIs and SDKs handle read and write operations.
Storage supports high-performance uploads and downloads of large files. Combined with Auth row-level security (RLS) policies, it enables fine-grained access control for storage buckets, allowing you to define who can view, upload, or delete files through a single policy.
Related Concepts
| Concept | Description |
|---|---|
| Storage bucket | The top-level container for storing files. A bucket can be public or private. Each storage bucket corresponds to a subdirectory in the Huawei Cloud OBS bucket. |
| Folder | A hierarchical structure within a storage bucket used to organize files. |
| File | Files such as images and documents are binary resources stored in OBS to avoid using database storage for large files. |
| Storage backend | File storage integrates with Huawei Cloud OBS at the underlying layer. Operations, like uploading, downloading, and previewing files, are handled by OBS buckets. |
Mapping Between Storage Buckets and OBS Buckets
One Huawei Cloud OBS bucket stores all files for an RDS Supabase instance. Each Supabase storage bucket corresponds to a subdirectory in an OBS bucket.
The following example uses two storage buckets for an e-commerce scenario: product-images (public, storing product images) and product-specs (private, storing product specification documents). The following console procedures, SDK examples, and security policies use these two buckets. Refer to this mapping to understand which subdirectory within the OBS bucket each operation targets.
OBS bucket (Huawei Cloud) ├── product-images/ ← Public storage bucket (product images) └── product-specs/ ← Private storage bucket (product specification documents)
File Types and Size Limits
Storage supports uploading binary files of any type, including images, documents, audio and video files, and archives. You can restrict allowed file types for each storage bucket by configuring MIME types.
The maximum file size can be configured for each storage bucket. Multipart uploads are recommended for extra-large files.
Prerequisites
| Prerequisite | Description |
|---|---|
| Huawei Cloud real-name verification | Complete real-name verification before using file storage. Otherwise, the underlying file storage service cannot connect to OBS. |
| OBS bucket and AK/SK | Create an OBS bucket in the Huawei Cloud OBS console, and create an AK/SK with OBS permissions in the IAM console. Follow the principle of least privilege. |
| Network connectivity | The client must be able to access the Supabase application's IP address and port. |
| Same region | The OBS bucket should reside in the same region as the RDS Supabase instance. |
Enabling the Feature
File storage integrates with Huawei Cloud OBS at the underlying layer. Before using this feature, complete the Storage configuration on the Huawei Cloud console to enable it. The procedure is as follows:
- Create an OBS bucket on the Huawei Cloud OBS console, and create an AK/SK with OBS permissions on the IAM console.
- On the RDS Supabase console, specify the OBS bucket name, AK, and SK in the Basic Info area of the application details page to enable it.
For details, see Enabling or Disabling Storage Configuration.
Files and directories managed or created through file storage must not be modified or deleted directly in OBS while the application is using them. All such operations must be performed through the Supabase Storage API to prevent inconsistencies in file metadata on the Supabase side.
Managing Files in the Console
- Creating a Storage Bucket
Creating a storage bucket in the console is equivalent to creating a new subdirectory in the OBS bucket (see the mapping described in Related Concepts). Storage buckets are used to store files and isolate them by business purpose.
- Log in to Supabase Dashboard.
- In the navigation pane, choose Storage and click New bucket. Figure 1 Instructions for creating a storage bucket in Supabase Dashboard
- On the storage bucket creation page, configure the required parameters. Figure 2 Configuring parameters for creating a storage bucket in Supabase Dashboard
- Bucket name: Enter a name for the business bucket. This name corresponds to the subdirectory name in the OBS bucket.
- Public bucket configuration examples:
- product-images (storing product images): Enable Public bucket.
- product-specs (storing product specification documents): Disable Public bucket.
- File size limit and MIME type configuration examples:
- product-images: Set the file size limit to 10 MB and allow the MIME types image/png, image/jpeg, image/webp, and image/gif.
- product-specs: Set the file size limit to 50 MB and allow the MIME type application/pdf.
- Click Create to complete bucket creation. Figure 3 Bucket list
- Uploading and Managing Files
- Click the target storage bucket to open its details page.
- Click Create folder to create a subdirectory for storing files. Figure 4 Entry for creating a folder in a Supabase storage bucket
- Click Upload files to upload files. Figure 5 Uploading files in Supabase Dashboard
- Open the menu on the right side of a file to download it, obtain its URL, move it, or delete it.
Configuring Security Policies
Storage policies are built on PostgreSQL's Row-Level Security (RLS) mechanism. The storage schema's RLS must be enabled for policies to take effect.
- Log in to Supabase Dashboard.
- In the navigation pane, choose Storage. On the displayed page, click the Policies tab. Figure 6 List of storage bucket security policies in Supabase Dashboard
- Select the target storage bucket, click New Policy, and choose a template or create a custom policy. Figure 7 Creating a custom security policy for a storage bucket in Supabase Dashboard
- Configure the policy name, allowed operations, and target roles.
Example policy configurations:
- product-images (public bucket, allowing public read):
- Policy name: Public read for product-images
- Allowed operation: SELECT
- Target roles: anon
- Policy definition: bucket_id = 'product-images'
- product-specs (private bucket, allowing authenticated users to access their own folders):
- Policy name: Authenticated access for product-specs
- Allowed operation: INSERT and SELECT
- Target roles: authenticated
- Policy definition: bucket_id = 'product-specs' AND auth.uid()::text = (storage.foldername(name))[1]
- product-images (public bucket, allowing public read):
- Click Save policy.
- Allowing Public Read Access to a Specific Storage Bucket Example scenario: Configure public read access for the product-images bucket so that anyone (including unauthenticated visitors) can view product images directly through their URLs. This method is suitable for publicly displayed content on official websites, product detail pages, and similar scenarios.
CREATE POLICY "Public read for product-images" ON storage.objects FOR SELECT USING ( bucket_id = 'product-images' );
- Allowing Authenticated Users to Access Only Their Own Folders Example scenario: Configure user-level access isolation for the product-specs bucket. Signed-in users can read and write files only in folders named after their own user IDs. They cannot view or modify other users' product specification documents. This method is suitable for storing private documents for individual users.
-- Upload: Only to the user's own folder CREATE POLICY "Authenticated upload in user folder" ON storage.objects FOR INSERT TO authenticated WITH CHECK(bucket_id = 'product-specs' AND auth.uid()::text = (storage.foldername(name))[1]); -- Read: Only from the user's own folder CREATE POLICY "Authenticated read in user folder" ON storage.objects FOR SELECT TO authenticated USING(bucket_id = 'product-specs' AND auth.uid()::text = (storage.foldername(name))[1]);
These examples assume that the top-level folders within a storage bucket are named using user IDs (auth.uid()), with access isolated by folder.
Managing Files Using the SDK
Before performing file operations using the SDK, ensure that the target storage bucket has appropriate security policies configured. Reading files from public buckets does not require a policy.
The following examples use two storage buckets: product-images (public, for storing product images) and product-specs (private, for storing product specification documents).
- Creating a Storage Bucket
Example scenario: Creating a storage bucket using code is equivalent to creating a business-specific subdirectory in the OBS bucket. In an e-commerce scenario, create a public bucket for product images and a private bucket for product specification documents, allowing images to be viewed publicly while restricting access to specification documents to authorized users.
// Create a public storage bucket. await supabase.storage.createBucket('product-images', { public: true }) // Create a private storage bucket. await supabase.storage.createBucket('product-specs', { public: false }) - Uploading a File
Example scenario: Upload a local file to a specified path in a bucket. When the operations team uploads an image for a new product in the backend, the frontend uploads the selected image to the product-images bucket. After a successful upload, the image is stored in OBS and can be displayed directly on the product detail page.
const file = event.target.files[0] const { data, error } = await supabase.storage .from('product-images') .upload('ecs/console.png', file, { cacheControl: '3600', upsert: false, }) if (error) { console.error('Upload failed', error) return } - Downloading a File
Example scenario: Retrieve file contents from a bucket. When a file needs to be previewed or processed on the frontend, such as when customer service staff view a user's product specification document, call the download method to retrieve the file data and convert it into a usable URL for rendering on the page or for further processing.
const { data, error } = await supabase.storage .from('product-images') .download('ecs/console.png') // data is a Blob object. const url = URL.createObjectURL(data) - Getting a Public URL or a Signed URL
Example scenario: Obtain a file access URL. Use a public URL to embed images from a public bucket directly on a page. For sensitive documents in a private bucket, generate a time-limited signed URL to allow temporary access to a specific object without exposing its URL indefinitely.
// Public storage bucket — Obtain the URL directly. const { data } = supabase.storage .from('product-images') .getPublicUrl('ecs/console.png') // URL format: https://{access_IP}:{access_port}/storage/v1/object/public/product-images/ecs/console.png // Obtain the access IP address and port number from Preparations. // Private storage bucket — Generate a temporary signed URL (valid for 60 seconds). const { data, error } = await supabase.storage .from('product-specs') .createSignedUrl('obs/pricing.pdf', 60)The URL returned by getPublicUrl is directly accessible only if the storage bucket is public. For private storage buckets, use createSignedUrl to generate a temporary signed URL.
- Listing Files
Example scenario: List the files in a specified directory within a bucket. When managing a product image library in the backend, list all images in a product directory with pagination so that the operations team can browse, select, and manage them.
const { data, error } = await supabase.storage .from('product-images') .list('ecs', { limit: 100, sortBy: { column: 'name', order: 'asc' } }) - Deleting Files
Example scenario: Remove files from a bucket. When a product is discontinued or an image is replaced, delete the old image to free up storage space and prevent dirty data from remaining. Multiple files can be deleted in a single operation.
await supabase.storage .from('product-images') .remove(['ecs/console.png', 'ecs/detail.png'])
Reference
The following open-source Supabase documents are provided for reference only.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot