Skip to content

Commit

Permalink
Merge pull request #14 from zero-copy-labs/main
Browse files Browse the repository at this point in the history
Improvements to examples
  • Loading branch information
tehnorm authored Apr 27, 2023
2 parents 335e79a + a7b8363 commit 0a3fb30
Show file tree
Hide file tree
Showing 25 changed files with 289 additions and 103 deletions.
18 changes: 12 additions & 6 deletions examples/handling-buckets/create-bucket.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<?php

include __DIR__.'/../header.php';

use Supabase\Storage\StorageClient;

$scheme = 'http';
$domain = 'localhost:3000';
$path = '/storage/v1';
$client = new StorageClient($api_key, $reference_id, $domain, $scheme, $path);
$result = $client->createBucket('test-bucket-new', ['public' => false]);
$output = json_decode($result->getBody(), true);
//giving unique id to our bucket
$testBucket = 'test-bucket'.uniqid();

//creating our client and passing API_KEY & REFERENCE_ID
$client = new StorageClient($api_key, $reference_id);

//Created a bucket and printing out thr result
$result = $client->createBucket($testBucket, ['public' => false]);
$output = json_decode($result->getBody(), true);
print_r($output);

//Deleting our examples
$client->deleteBucket($testBucket);
11 changes: 10 additions & 1 deletion examples/handling-buckets/delete-bucket.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<?php

include __DIR__.'/../header.php';

use Supabase\Storage\StorageClient;

//Creating unique ID
$testBucket = 'test-bucket'.uniqid();

//Creating our client and passing API_KEY & REFERENCE_ID
$client = new StorageClient($api_key, $reference_id);
$result = $client->deleteBucket('test-bucket-new');
//Creating a bucket as example to test our remove method.
$client->createBucket($testBucket, ['public' => false]);

//Deleting a bucket function and printing result.
$result = $client->deleteBucket($testBucket);
$output = json_decode($result->getBody(), true);
print_r($output);
12 changes: 11 additions & 1 deletion examples/handling-buckets/empty-bucket.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
<?php

include __DIR__.'/../header.php';

use Supabase\Storage\StorageClient;

//Creating out client to upload files
$client = new StorageClient($api_key, $reference_id);
$result = $client->emptyBucket('test-bucket');
//Assigning a unique ID to our bucket
$testBucket = 'test-bucket'.uniqid();
//creating a bucket to upload files into
$client->createBucket($testBucket, ['public' => false]);
//We will empty out our bucket with the following function and print our the response.
$result = $client->emptyBucket($testBucket);
$output = json_decode($result->getBody(), true);
print_r($output);

//Delete the example bucket
$client->deleteBucket($testBucket);
10 changes: 9 additions & 1 deletion examples/handling-buckets/get-bucket.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<?php

include __DIR__.'/../header.php';

use Supabase\Storage\StorageClient;

//Crete a client.
$client = new StorageClient($api_key, $reference_id);
$result = $client->getBucket('test-bucket');
//Creating a bucket with a unique ID.
$testBucket = 'test-bucket'.uniqid();
$client->createBucket($testBucket, ['public' => false]);
//Method to get a bucket, and print out result.
$result = $client->getBucket($testBucket);
$output = json_decode($result->getBody(), true);
print_r($output);
//Deleting example bucket
$client->deleteBucket($testBucket);
11 changes: 8 additions & 3 deletions examples/handling-buckets/list-buckets.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<?php

include __DIR__.'/../header.php';

use Supabase\Storage\StorageClient;

$scheme = 'http';
$domain = 'localhost:8000';
$path = '/storage/v1';
//Crete a client.
$client = new StorageClient($api_key, $reference_id);
//Creating a bucket with a unique ID.
$testBucket = 'test-bucket'.uniqid();
$client->createBucket($testBucket, ['public' => false]);
//Method to list all buckets, and print out result.
$result = $client->listBuckets();
$output = json_decode($result->getBody(), true);
print_r($output);
//Deleting example bucket
$client->deleteBucket($testBucket);
12 changes: 10 additions & 2 deletions examples/handling-buckets/update-bucket.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<?php

include __DIR__.'/../header.php';

use Supabase\Storage\StorageClient;

$client = new StorageClient($api_key, $reference_id);
$result = $client->updateBucket('test-bucket', ['public' => true]);
//Crete a client.
$client = new StorageClient($api_key, $reference_id);
//Creating a bucket with a unique ID.
$testBucket = 'test-bucket'.uniqid();
$client->createBucket($testBucket, ['public' => false]);
//Method to update a bucket, and print out result.
$result = $client->updateBucket($testBucket, ['public' => true]);
$output = json_decode($result->getBody(), true);
print_r($output);
//Deleting example bucket
$client->deleteBucket($testBucket);
15 changes: 13 additions & 2 deletions examples/handling-files/copy-file.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@

use Supabase\Storage\StorageFile;

//Selecting an already created bucket for our test.
$bucket_id = 'test-bucket';
$client = new StorageFile($api_key, $reference_id, $bucket_id);
$result = $client->copy('path/to/file.png', 'test-bucket', 'path/to/file-copy.png');
//Also creating file with unique ID.
$testFile = 'file'.uniqid().'.png';
//Creating our StorageFile instance to upload files.
$file = new StorageFile($api_key, $reference_id, $bucket_id);
//We will upload a test file to copy it.
$file->upload($testFile, 'https://gpdefvsxamnscceccczu.supabase.co/storage/v1/object/public/examples-bucket/supabase-logo.png', ['public' => false]);
//Now we will copy the file using the copy method.
$result = $file->copy($testFile, 'test-copy');
//print out result.
$output = json_decode($result->getBody(), true);
print_r($output);
//delete example files.
$file->remove(["$testFile"]);
$file->remove(['test-copy']);
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<?php

include __DIR__.'/../header.php';

use Supabase\Storage\StorageFile;

//Selecting an already created bucket for our test.
$bucket_id = 'test-bucket';

$client = new StorageFile($api_key, $reference_id, $bucket_id);
//Creating file with unique ID.
$testFile = 'file'.uniqid().'.png';
//Creating our StorageFile instance to upload files.
$file = new StorageFile($api_key, $reference_id, $bucket_id);
//We will upload a test file to retrieve the URL.
$file->upload($testFile, 'https://gpdefvsxamnscceccczu.supabase.co/storage/v1/object/public/examples-bucket/supabase-logo.png', ['public' => false]);
//print out the URL of the examples file.
$options = ['download' => true];
$result = $client->createSignedUrl('path/to/file-base64.png', 60, $options);
print_r($result);
$result = $file->createSignedUrl($testFile, 60, $options);
print_r($result->getBody()->getContents());
//delete example files.
$file->remove(["$testFile"]);
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<?php

include __DIR__.'/../header.php';

use Supabase\Storage\StorageFile;

//Selecting an already created bucket for our test.
$bucket_id = 'test-bucket';

$client = new StorageFile($api_key, $reference_id, $bucket_id);
$options = ['transform' => ['width'=> '100', 'height'=> '100']];
$result = $client->createSignedUrl('path/to/file-base64.png', 60, $options);
print_r($result);
//Creating file with unique ID.
$testFile = 'file'.uniqid().'.png';
//Creating our StorageFile instance to upload files.
$file = new StorageFile($api_key, $reference_id, $bucket_id);
//We will upload a test file to retrieve the URL.
$file->upload($testFile, 'https://gpdefvsxamnscceccczu.supabase.co/storage/v1/object/public/examples-bucket/supabase-logo.png', ['public' => false]);
//print out the URL of the examples file.
$options = ['transform' => ['width' => '100', 'height' => '100']];
$result = $file->createSignedUrl($testFile, 60, $options);
print_r($result->getBody()->getContents());
//delete example files.
$file->remove(["$testFile"]);
17 changes: 12 additions & 5 deletions examples/handling-files/create-signed-url-file.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@

use Supabase\Storage\StorageFile;

//Selecting an already created bucket for our test.
$bucket_id = 'test-bucket';

$client = new StorageFile($api_key, $reference_id, $bucket_id);
$options = ['public' => true];
$result = $client->createSignedUrl('path/to/file.png', 60, $options);
print_r($result);
//Also creating file with unique ID.
$testFile = 'file'.uniqid().'.png';
//Creating our StorageFile instance to upload files.
$file = new StorageFile($api_key, $reference_id, $bucket_id);
//We will upload a test file to retrieve the URL.
$file->upload($testFile, 'https://gpdefvsxamnscceccczu.supabase.co/storage/v1/object/public/examples-bucket/supabase-logo.png', ['public' => false]);
//print out the URL of the examples file.
$result = $file->createSignedUrl($testFile, 60, ['public' => true]);
print_r((string) $result->getBody());
//delete example files.
$file->remove(["$testFile"]);

// should be print_r((string) $result->getBody()); and delete the options variable
18 changes: 14 additions & 4 deletions examples/handling-files/create-signed-url-files.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@

use Supabase\Storage\StorageFile;

//Selecting an already created bucket for our test.
$bucket_id = 'test-bucket';

$client = new StorageFile($api_key, $reference_id, $bucket_id);
$options = ['public' => true];
$result = $client->createSignedUrls(['test-file.jpg', 'path/to/file-base64.png'], 60, $options);
//Also creating file with unique ID.
$testFile = 'file'.uniqid().'.png';
$testFile2 = 'file'.uniqid().'.png';
//Creating our StorageFile instance to upload files.
$file = new StorageFile($api_key, $reference_id, $bucket_id);
//We will upload a test file to retrieve the URL.
$file->upload($testFile, 'https://gpdefvsxamnscceccczu.supabase.co/storage/v1/object/public/examples-bucket/supabase-logo.png', ['public' => false]);
$file->upload($testFile2, 'https://gpdefvsxamnscceccczu.supabase.co/storage/v1/object/public/examples-bucket/supabase-logo.png', ['public' => false]);
//print out the URL of the examples file.
$result = $file->createSignedUrls([$testFile, $testFile2], 60, ['public' => true]);
print_r($result);
//delete example files.
$file->remove(["$testFile"]);
$file->remove(["$testFile2"]);
20 changes: 20 additions & 0 deletions examples/handling-files/download-file-with-transformations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

include __DIR__.'/../header.php';

use Supabase\Storage\StorageFile;

//Selecting an already created bucket for our test.
$bucket_id = 'test-bucket';
//Also creating file with unique ID.
$testFile = 'file'.uniqid().'.png';
//Creating our StorageFile instance to upload files.
$file = new StorageFile($api_key, $reference_id, $bucket_id);
//We will upload a test file.
$file->upload($testFile, 'https://gpdefvsxamnscceccczu.supabase.co/storage/v1/object/public/examples-bucket/supabase-logo.png', ['public' => false]);
//print out result and download the file to our directory.
$result = $file->download($testFile, ['transform' => ['width' => 50, 'height' => 50]]);
$output = $result->getBody()->getContents();
file_put_contents('file.png', $output);
//delete example files.
$file->remove(["$testFile"]);
13 changes: 0 additions & 13 deletions examples/handling-files/download-file-with-transformatios.php

This file was deleted.

16 changes: 12 additions & 4 deletions examples/handling-files/download-file.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<?php

include __DIR__.'/../header.php';

use Supabase\Storage\StorageFile;

//Selecting an already created bucket for our test.
$bucket_id = 'test-bucket';

$client = new StorageFile($api_key, $reference_id, $bucket_id);
$result = $client->download('path/to/file.png');
//Also creating file with unique ID.
$testFile = 'file'.uniqid().'.png';
//Creating our StorageFile instance to upload files.
$file = new StorageFile($api_key, $reference_id, $bucket_id);
//We will upload a test file.
$file->upload($testFile, 'https://gpdefvsxamnscceccczu.supabase.co/storage/v1/object/public/examples-bucket/supabase-logo.png', ['public' => false]);
//we will download the file to our directory using the download method.
$result = $file->download($testFile);
$output = $result->getBody()->getContents();
file_put_contents('file.png', $output);
print_r($output);
//delete example files.
$file->remove(["$testFile"]);
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<?php

include __DIR__.'/../header.php';

use Supabase\Storage\StorageFile;

//Selecting an already created bucket for our test.
$bucket_id = 'test-bucket';

$client = new StorageFile($api_key, $reference_id, $bucket_id);
$options = ['transform' => ['width'=> 50, 'height'=> 50]];
$result = $client->getPublicUrl('path/to/file-base64.png', $options);
//Also creating file with unique ID.
$testFile = 'file'.uniqid().'.png';
//Creating our StorageFile instance to upload files.
$file = new StorageFile($api_key, $reference_id, $bucket_id);
//We will upload a test file to retrieve the URL.
$file->upload($testFile, 'https://gpdefvsxamnscceccczu.supabase.co/storage/v1/object/public/examples-bucket/supabase-logo.png', ['public' => false]);
//print out the URL of the examples file.
$result = $file->getPublicUrl($testFile, ['transform' => ['width' => 50, 'height' => 50]]);
print_r($result);
//delete example files. Comment out the file->remove to be able to download the file from the browser.
$file->remove(["$testFile"]);
16 changes: 12 additions & 4 deletions examples/handling-files/get-public-url-file.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<?php

include __DIR__.'/../header.php';

use Supabase\Storage\StorageFile;

//Selecting an already created bucket for our test.
$bucket_id = 'test-bucket';

$client = new StorageFile($api_key, $reference_id, $bucket_id);
$options = ['download' => true];
$result = $client->getPublicUrl('path/to/file.png', $options);
//Also creating file with unique ID.
$testFile = 'file'.uniqid().'.png';
//Creating our StorageFile instance to upload files.
$file = new StorageFile($api_key, $reference_id, $bucket_id);
//We will upload a test file to retrieve the URL.
$file->upload($testFile, 'https://gpdefvsxamnscceccczu.supabase.co/storage/v1/object/public/examples-bucket/supabase-logo.png', ['public' => false]);
//print out the URL of the examples file that will trigger a download.
$result = $file->getPublicUrl($testFile, ['download' => true]);
print_r($result);
//delete example files. Comment out the file->remove to be able to download the file from the browser.
$file->remove(["$testFile"]);
16 changes: 11 additions & 5 deletions examples/handling-files/list-files.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

use Supabase\Storage\StorageFile;

// Selecting an already created bucket for our test.
$bucket_id = 'test-bucket';

$client = new StorageFile($api_key, $reference_id, $bucket_id);
$options = ['limit' => 100, 'offset' => 0, 'sortBy' => ['column' => 'name', 'order' => 'asc']];
$result = $client->list('path/to', $options);

// Also creating file with unique ID.
$testFile = 'file'.uniqid().'.png';
// Creating our StorageFile instance to upload files.
$file = new StorageFile($api_key, $reference_id, $bucket_id);
// We will upload a test file to copy it.
$file->upload($testFile, 'https://gpdefvsxamnscceccczu.supabase.co/storage/v1/object/public/examples-bucket/supabase-logo.png', ['public' => false]);
// Print out the list of results.
$result = $file->list('examples-bucket', ['limit' => 100, 'offset' => 0, 'sortBy' => ['column' => 'name', 'order' => 'asc']]);
$output = json_decode($result->getBody(), true);
print_r($output);
//delete example files.
$file->remove(["$testFile"]);
Loading

0 comments on commit 0a3fb30

Please sign in to comment.