PHP Client library to interact with Supabase Storage.
composer require supabase/storage-php
use Supabase\Storage;
$url = 'https://<project_ref>.supabase.co/storage/v1';
$service_key = '<service_role>';
$storage = new Storage\StorageClient($url, [
'Authorization' => 'Bearer ' . $service_key,
]);
-
Create a new Storage bucket:
$opts = [ 'public' => true ]; //Bucket options $result = $storage->createBucket('my-new-storage-bucket', $opts);
-
Retrieve the details of an existing Storage bucket:
$result = $storage->getBucket('test_bucket');
-
Update a new Storage bucket:
$opts = [ 'public' => true ]; //Bucket options. $result = $storage->updateBucket('test_bucket' /* Bucket name */, $opts);
-
Remove all objects inside a single bucket:
$result = $storage->emptyBucket('test_bucket');
-
Delete an existing bucket (a bucket can't be deleted with existing objects inside it):
$result = $storage->deleteBucket('test_bucket');
-
Retrieve the details of all Storage buckets within an existing project:
$result = $storage->listBuckets();
use Supabase\Storage\StorageFile;
$url = 'https://<project_ref>.supabase.co/storage/v1';
$service_key = '<service_role>';
$bucket_id = '<storage-bucket-id';
$storage = new StorageFile($url, [
'Authorization' => 'Bearer ' . $service_key,
], $bucket_id);
-
Upload a file to an existing bucket:
$file_path = $path; // where to uploaded [folder with file name] $file_body = $file; // load your file here $opts = $options; //The options for the upload. $result = $storage->upload($file_path, $file_body, $options);
-
Download a file from an exisiting bucket:
$file_path = $path; // path to file $opts = $options; //The options for the download. $result = $storage->download($file_path, $options)
-
List all the files within a bucket:
//pending const { data, error } = await storageClient.from('bucket').list('folder')
Note: The
list
method also accepts a map of optional parameters. For a complete list see the Supabase API reference. -
Replace an existing file at the specified path with a new one:
$path = 'path/to/file'; $file_body = $file; // load your file here $opts = $options; //The options for the upload. $result = $storage->update($path, $file_body, $opts);
Note: The
upload
method also accepts a map of optional parameters. For a complete list see the Supabase API reference. -
Move an existing file:
$path = 'path/to/file'; $new_path = 'new/path/to/file'; $result = $storage->move($path, $new_path);
-
Delete files within the same bucket:
$path = 'path/to/file'; $result = $storage->remove($path);
-
Create signed URL to download file without requiring permissions:
$path = 'path/to/file'; $expire_in = 60; $opts = $options; //The options for the download.[ 'download' => TRUE ] $storage->createSignedUrl($path, $expire_in, $opts);
-
Retrieve URLs for assets in public buckets:
$path = 'path/to/file'; $opts = $options; //The options for the download.[ 'download' => TRUE ] $storage->testGetPublicUrl($path, $opts);