supabase-rb-rb
Storage

Overview

Bucket admin API and file operations.

The storage surface reaches Supabase Storage via the top-level Supabase::Client. It exposes two layers:

  • Bucket admin APIcreate_bucket, get_bucket, list_buckets, update_bucket, delete_bucket, empty_bucket. Methods called directly on supabase.storage.
  • File APIupload, download, list, move, copy, remove, signed-URL helpers, public-URL helpers. Reached via supabase.storage.from(bucket_id).
supabase = Supabase.create_client(
  supabase_url: ENV.fetch("SUPABASE_URL"),
  supabase_key: ENV.fetch("SUPABASE_SERVICE_ROLE_KEY") # bucket admin needs service-role
)

supabase.storage.create_bucket("avatars", public: true)
supabase.storage.list_buckets   # => [Supabase::Storage::Types::Bucket(...)]
supabase.storage.from("avatars").upload("ada.png", File.binread("ada.png"))

Bucket admin API

MethodDescription
create_bucketCreate a new bucket. public: true for unauthenticated reads.
get_bucketFetch a single bucket record by id.
list_bucketsList every bucket the caller can see.
update_bucketPatch a bucket's public / file_size_limit / allowed_mime_types.
empty_bucketDelete every object inside a bucket without removing the bucket.
delete_bucketDelete the bucket itself. Bucket must be empty.

File API

Scoped to one bucket via supabase.storage.from(bucket_id) (aliases: from_ and bucket).

MethodDescription
uploadUpload an object. Accepts String bytes, File/IO, or Pathname.
downloadDownload object bytes. Optional transform: routes through the image renderer.
listList objects under a prefix. Returns the raw response Array<Hash>.
moveMove (rename) an object inside the same bucket.
copyCopy an object inside the same bucket.
removeDelete one or more objects by path.
create_signed_urlMint a time-limited URL for one object.
create_signed_urlsMint signed URLs in bulk for many objects.
create_signed_upload_urlMint a pre-signed URL that lets a client upload without your service-role key.
upload_to_signed_urlConsume a pre-signed URL to upload bytes. Server-side helper.
get_public_urlBuild the public URL for an object in a public: true bucket.

Bucket type

get_bucket and list_buckets return Supabase::Storage::Types::Bucket structs with these fields:

FieldTypeDescription
idStringStable identifier (the slug used in URLs).
nameStringDisplay name. Defaults to id on create.
ownerStringUUID of the user that created the bucket.
publicBooleantrue if anonymous reads are allowed via the public URL.
file_size_limitInteger, nilMaximum object size in bytes. nil means unbounded.
allowed_mime_typesArray<String>, nilAllowlist of content types. nil means any.
created_atStringISO-8601 timestamp.
updated_atStringISO-8601 timestamp.
typeString, nil"STANDARD" for object buckets. Present only on newer storage-api versions.

Authentication

Bucket admin operations require the service-role key — the anon key is rejected by Supabase Storage for every endpoint in this group. Construct the client with the service-role JWT in supabase_key: (or pass a custom Authorization: Bearer ... header) before calling any method on this page.

Service-role key required

Every method on this page requires the service-role JWT. Bucket admin endpoints reject the publishable / anon key with 401 Unauthorized. Keep the service-role key on the server — never ship it to a browser.

On this page