mrcoco/ceph-uny

Provides a CephClient for storing files UNY cloud object storage.

dev-master 2019-09-18 04:59 UTC

This package is auto-updated.

Last update: 2024-04-18 14:59:32 UTC


README

Provides a CephClient for storing files UNY cloud object storage

install via composer

composer require mrcoco/ceph-uny dev-master
include 'vendor/autoload.php';

use CephUny\Client;
$config = array(
    'version' => 'latest',
    'region'  => '',
    'endpoint' => 'AWS_HOST',
    'credentials' => array(
        'key' => 'AWS_KEY',
        'secret' => 'AWS_SECRET_KEY',
    )
);
$client = new Client($config);
$bucketName = 'my-bucket';

create bucket;

$client->createBucket($bucketName);

Dump all existing buckets.

foreach ($client->getBuckets() as $bucket) {
 var_dump($bucket);
}

put direct file

$file = "uny.png";
try{
    $client->putFromFile($bucketName,$file);
}catch (Aws\S3\Exception\S3Exception $e){
    echo "There was an error uploading the file.\n";
}

put direct file return URL

$file = "uny.png";
try{
    $result = $client->putFromFile($bucketName,$file);
    echo $result['ObjectURL'].PHP_EOL;
    
}catch (Aws\S3\Exception\S3Exception $e){
    echo "There was an error uploading the file.\n";
}

Get file from bucket

$fileName = basename($file);
$result = $client->getFile($bucketName, $fileName);
var_dump($result);

get preSign URL expired

$bucketName = "mybocket";
$file = "uny.png";
$fileName = basename($file);
$expired = "+30 minutes";
$url = $client->preSignUrl($bucketName, $fileName,$expired);
echo $url;