Get bucket size
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
- [x] Follow our Code of Conduct
- [x] Read the Contributing Guidelines.
- [x] Read the docs.
- [x] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
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
Hi! I’d like to explore this feature.
Before starting implementation:
- Should this be implemented purely in supabase-js?
- Does the Storage HTTP API currently expose bucket size?
- Is get_size_by_bucket considered stable for public SDK usage?
Happy to open a draft PR once direction is confirmed.
@selvaganapathycoder should probably try to ping the supabase team
@w3b6x9 ? @filipecabaco ? not really sure who to tag tbh
will share with the storage team
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.
I am closing this issue, based on the reply above by @ferhatelmas from our storage team.