supabase-js icon indicating copy to clipboard operation
supabase-js copied to clipboard

Get bucket size

Open PaperPrototype opened this issue 9 months ago • 6 comments

Description

As noted here https://www.answeroverflow.com/m/1186881391233863751

Basically some way to get the current bucket size via the storage API. Something like supabase.storage.from("mybucket").getSize()

Suggested solution

There is seems to already be an RPC function called "get_size_by_bucket", so just reuse that?

Alternative

Calling supabase.rpc("get_size_by_bucket") manually, though it is not documented and I don't know if it will break in future versions (or if it is already broken in the latest release)

Additional context

No response

Validations

PaperPrototype avatar Feb 06 '26 20:02 PaperPrototype

Doing this mainly as a way of trying to control max total storage per bucket for a SaaS app with free tier storage. The idea is to use one bucket per user project and limit the projects max storage.

Something like a maxBucketSize could also serve this purpose.

const { data, error } = await supabase.storage.createBucket('avatars', {
  public: true,
  allowedMimeTypes: ['image/*'],
  maxFileSize: '1MB',     <--  max size for each file in the bucket
  maxBucketSize:'1GB'   <-- max size of the entire bucket. 
})

Related discussion here https://github.com/supabase/storage/issues/134#issuecomment-1811864025

PaperPrototype avatar Feb 06 '26 20:02 PaperPrototype

Hi! I’d like to explore this feature.

Before starting implementation:

  1. Should this be implemented purely in supabase-js?
  2. Does the Storage HTTP API currently expose bucket size?
  3. Is get_size_by_bucket considered stable for public SDK usage?

Happy to open a draft PR once direction is confirmed.

selvaganapathycoder avatar Feb 18 '26 09:02 selvaganapathycoder

@selvaganapathycoder should probably try to ping the supabase team

@w3b6x9 ? @filipecabaco ? not really sure who to tag tbh

PaperPrototype avatar Feb 18 '26 19:02 PaperPrototype

will share with the storage team

filipecabaco avatar Feb 18 '26 22:02 filipecabaco

Adding bucket configuration and validating on each upload is a costly operation. There is no plan to support it.

Existing function is unlikely to go away but it's better to treat as internal that could change anytime and not depend on. Beware that it executes a count and it can impact performance of your database.

That being said, you could maintain the variant yourself via a trigger to keep size precomputed and read it from your own function cheaply.

ferhatelmas avatar Feb 20 '26 16:02 ferhatelmas

I am closing this issue, based on the reply above by @ferhatelmas from our storage team.

mandarini avatar Jun 04 '26 11:06 mandarini