Storage

Appizap storage comprises of files, folders, and buckets.

Files

Various types of media files can be uploaded, such as images, GIFs, and videos. It is recommended to store these files separately from the database due to their large sizes. Additionally, HTML files are retrieved in plain text format for security reasons.

Folders

Folders act as a method of arranging and categorizing your documents, much like the system on your computer. The manner in which you choose to structure your files within these folders is a matter of personal preference, without a definitive approach. The organizational system can be tailored to best fit the needs of your specific project.

Buckets

Buckets serve as individual repositories for storing files and folders, akin to advanced folders in terms of functionality and purpose. It is advisable to establish unique buckets specifically for organizing Security and Access Rules. For instance, one may designate a "video" bucket for video files and an "avatar" bucket for profile pictures.

File, Folder, and Bucket names must follow AWS object key naming guidelines and avoid use of any other characters.

Creating a bucket

Utilizing the Dashboard enables the creation of a bucket. This storage facility seamlessly integrates with your Postgres database, allowing the use of SQL and our client libraries for data management.

-- Use Postgres to create a bucket.

insert into storage.buckets
  (id, name)
values
  ('avatars', 'avatars');

Upload a File

The user can easily upload a file either through the Dashboard interface or by utilizing our JavaScript libraries within a web browser.

//Using Javascript
const avatarFile = event.target.files[0]
const { data, error } = await supabase.storage
  .from('avatars')
  .upload('public/avatar1.png', avatarFile)

Download a File

  1. Go to the storage page in the Dashboard.

  2. Select the bucket that contains the file.

  3. Select the file that you want to download.

  4. Click Download.

// Use the JS library to download a file.

const { data, error } = await supabase.storage.from('avatars').download('public/avatar1.png')

Add Security Rules

Access to your files can be limited by utilizing either the Dashboard or SQL.

  1. Go to the storage page in the Dashboard.

  2. Click Policies in the sidebar.

  3. Click Add Policies in the OBJECTS table to add policies for Files. You can also create policies for Buckets.

  4. Choose whether you want the policy to apply to downloads (SELECT), uploads (INSERT), updates (UPDATE), or deletes (DELETE).

  5. Give your policy a unique name.

  6. Write the policy using SQL.

-- Use SQL to create a policy.

create policy "Public Access"
  on storage.objects for select
  using ( bucket_id = 'public' );

Last updated