pub struct StorageClient { /* private fields */ }Expand description
Client for the Supabase Storage API at <project>/storage/v1.
Cloning is cheap; clones share the HTTP connection pool.
Implementations§
Source§impl StorageClient
impl StorageClient
Sourcepub fn new(project_url: &Url, api_key: &str) -> Result<Self, StorageError>
pub fn new(project_url: &Url, api_key: &str) -> Result<Self, StorageError>
Creates a client for the project at project_url (for example https://abc.supabase.co/).
Requests send apikey: <api_key>. A legacy JWT key is also sent as
Authorization: Bearer <api_key>. A new-format key (sb_publishable_... or
sb_secret_...) is not a JWT, so the client sends no Authorization header until
StorageClient::with_access_token sets one.
§Errors
Returns an error when the URL cannot be a base, api_key is not a valid header value, or
the HTTP client cannot be built.
Sourcepub fn new_with_client(
project_url: &Url,
api_key: &str,
http: Client,
) -> Result<Self, StorageError>
pub fn new_with_client( project_url: &Url, api_key: &str, http: Client, ) -> Result<Self, StorageError>
Like StorageClient::new, but reuses the connection pool of http.
§Errors
Returns an error when the URL cannot be a base or api_key is not a valid header value.
Sourcepub fn with_access_token(&self, token: &str) -> Result<Self, StorageError>
pub fn with_access_token(&self, token: &str) -> Result<Self, StorageError>
Returns a copy that sends Authorization: Bearer <token> (a user JWT) so that row level
security policies apply to that user. The apikey header stays unchanged.
§Errors
Returns an error when token is not a valid header value.
Sourcepub fn with_project_url(&self, project_url: &Url) -> Result<Self, StorageError>
pub fn with_project_url(&self, project_url: &Url) -> Result<Self, StorageError>
Returns a copy that sends requests to the project at project_url (joined with
storage/v1). All headers, including any access token, stay unchanged.
§Errors
Returns an error when the URL cannot be a base.
Sourcepub const fn from<'a>(&'a self, bucket: &'a str) -> Bucket<'a>
pub const fn from<'a>(&'a self, bucket: &'a str) -> Bucket<'a>
Returns a handle for object operations in bucket. No request is sent.
Sourcepub async fn list_buckets(&self) -> Result<Vec<BucketInfo>, StorageError>
pub async fn list_buckets(&self) -> Result<Vec<BucketInfo>, StorageError>
Lists all buckets visible to the current credentials.
§Errors
Returns an error on transport failure, non-success status, or an unexpected body.
Sourcepub async fn get_bucket(&self, id: &str) -> Result<BucketInfo, StorageError>
pub async fn get_bucket(&self, id: &str) -> Result<BucketInfo, StorageError>
Fetches one bucket.
§Errors
Returns an error on an invalid id, transport failure, non-success status, or an unexpected body.
Sourcepub async fn create_bucket(
&self,
id: &str,
options: &BucketOptions,
) -> Result<(), StorageError>
pub async fn create_bucket( &self, id: &str, options: &BucketOptions, ) -> Result<(), StorageError>
Creates a bucket whose id and name are id.
§Errors
Returns an error on an invalid id, transport failure, or non-success status.
Sourcepub async fn update_bucket(
&self,
id: &str,
options: &BucketOptions,
) -> Result<(), StorageError>
pub async fn update_bucket( &self, id: &str, options: &BucketOptions, ) -> Result<(), StorageError>
Replaces the settings of a bucket.
§Errors
Returns an error on an invalid id, transport failure, or non-success status.
Sourcepub async fn empty_bucket(&self, id: &str) -> Result<(), StorageError>
pub async fn empty_bucket(&self, id: &str) -> Result<(), StorageError>
Deletes all objects in a bucket and keeps the bucket.
§Errors
Returns an error on an invalid id, transport failure, or non-success status.
Sourcepub async fn delete_bucket(&self, id: &str) -> Result<(), StorageError>
pub async fn delete_bucket(&self, id: &str) -> Result<(), StorageError>
Deletes a bucket. The API rejects this when the bucket is not empty; call
StorageClient::empty_bucket first.
§Errors
Returns an error on an invalid id, transport failure, or non-success status.