supabase-rb-rb
Storage

Empty a bucket

Delete every object inside a bucket without removing the bucket itself.

Delete every object inside a bucket without removing the bucket itself. The bucket id, public flag, size limit, and MIME allowlist are preserved — only the contents are wiped.

Use this when you want to reset a bucket (e.g. a development scratch area) without re-creating it and re-applying configuration. It's also the standard prelude to delete_bucket, which refuses to drop a non-empty bucket.

This operation is irreversible. Every object is removed in a single server-side sweep — there's no per-object confirmation, no soft-delete, and no dry_run flag.

Service-role key required

Bucket admin endpoints reject the publishable / anon key with 401 Unauthorized. Construct the client with the service-role JWT.

Signature

supabase.storage.empty_bucket(id)

Parameters

NameTypeRequiredDescription
idStringRequiredBucket identifier to empty. The bucket record stays — only its objects are deleted.

Returns

Returns
Hash

The raw storage-api response body, typically { "message" => "Successfully emptied" }.

Example — wipe a scratch bucket

supabase.storage.empty_bucket("scratch")
# => { "message" => "Successfully emptied" }

supabase.storage.from("scratch").list("")
# => [] — bucket is intact, but contains no objects

Example — empty then delete

supabase.storage.empty_bucket("old-uploads")
supabase.storage.delete_bucket("old-uploads")

Example — confirm before wiping

files = supabase.storage.from("user-uploads").list("")
print "About to delete #{files.size} object(s). Type YES to confirm: "
if $stdin.gets.chomp == "YES"
  supabase.storage.empty_bucket("user-uploads")
end

On this page