Skip to content
Storage

存储桶

桶可以帮助你整理文件,并决定你资源的访问模型。像最大文件大小和允许的内容类型这样的上传限制也是在桶级别定义的。

🌐 Buckets allow you to keep your files organized and determines the Access Model for your assets. Upload restrictions like max file size and allowed content types are also defined at the bucket level.

访问模型 #

🌐 Access model

桶有两种访问模式,公共私有桶。

🌐 There are 2 access models for buckets, public and private buckets.

私有存储桶 #

🌐 Private buckets

当一个存储桶被设置为私有时,所有操作都需要通过RLS 策略进行访问控制。下载资源时也适用。存储桶默认为私有。

🌐 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 is to:

  • 通过提供包含用户 JWT 的授权头,使用下载方法。你在 storage.objects 表上创建的 RLS 策略将使用该用户来判断他们是否有访问权限。
  • 使用 createSignedUrl 方法 创建一个带签名的 URL,该 URL 可以在有限时间内访问。

示例用例: #

🌐 Example use cases:

  • 上传用户的敏感文件
  • 使用 RLS 设置精细访问控制来保护私有资源

公共存储桶 #

🌐 Public buckets

当一个存储桶被标记为“公开”时,它实际上会绕过访问控制,既可以获取文件,也可以提供文件。这意味着任何拥有资源 URL 的人都可以轻松访问该文件。

🌐 When a bucket is designated as 'Public,' it effectively bypasses access controls for both retrieving and serving files within the bucket. This means that anyone who possesses the asset URL can readily access the file.

访问控制仍然适用于其他类型的操作,包括上传、删除、移动和复制。

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

示例用例: #

🌐 Example use cases:

  • 用户头像
  • 用户公共媒体
  • 博客文章内容

公共存储桶比私有存储桶性能更好,因为它们的缓存方式不同。

🌐 Public buckets are more performant than private buckets since they are cached differently.