Skip to content

Updated

Storage buckets

Knowing the difference between public and private buckets tells you which kind to create for each kind of file. For how to create a bucket, see Creating buckets.

Access model

Buckets keep your files organized and determine the access model for your assets. There are two access models for buckets, public and private:

Access modelRetrieving and serving filesOther operations
PrivateDownloads with the user's JWT are subject to RLS policies. A signed URL gives access until it expires.Subject to RLS policies
PublicAnyone with the asset URLAccess control enforced

Upload restrictions like max file size and allowed content types are also defined at the bucket level.

Private buckets

When a bucket is set to Private, all operations are subject to access control via RLS policies. This also applies when downloading assets. Buckets are private by default.

The only ways to download assets within a private bucket are:

  • Use the download method by providing an authorization header containing your user's JWT. The RLS policy you create on the storage.objects table uses this user to determine if they have access.
  • Create a signed URL with the createSignedUrl method that can be accessed for a limited time.

The following are example use cases for private buckets:

  • Uploading users' sensitive documents
  • Securing private assets by using RLS to set up fine-grain access controls

Public buckets

When a bucket is set to Public, it bypasses access controls for both retrieving and serving files within the bucket. Anyone with the asset URL can access the file.

Access control is still enforced for other types of operations including uploading, deleting, moving, and copying.

The following are example use cases for public buckets:

  • User profile pictures
  • User public media
  • Blog post content

Public buckets get a better cache hit rate than private buckets, because they're cached differently.