Laravel 5 Conoha Object Handler
, (*1)
Laravel 5 Package to use Conoha Object Storage., (*2)
Installation
Install the package via Composer., (*3)
composer require okashoi/laravel5-conoha-object-handler
To use the package, register the service provider in config/app.php., (*4)
'providers' => [
// ...
Okashoi\Laravel5ConohaObjectHandler\ConohaObjectServiceProvider::class,
]
To configure your connection settings, execute the following command., (*5)
php artisan vendor:publish --provider="Okashoi\Laravel5ConohaObjectHandler\ConohaObjectServiceProvider"
Then set the following environment variables in .env file., (*6)
CONOHA_TENANT_ID
CONOHA_USERNAME
CONOHA_PASSWORD
Usage
Create the Instance
First of all you have to create an ObjectHandler instance., (*7)
use Okashoi\Laravel5ConohaObjectHandler\ObjectHandler;
$handler = new ObjectHandler();
Optionally, you can cache the auth token by specifying the cache key.
(It is recommended. By default, the instance gets a new auth token per a request.), (*8)
use Okashoi\Laravel5ConohaObjectHandler\ObjectHandler;
// cache the auth token with key 'conoha_token'
$handler = new ObjectHandler('conoha_token');
Caching is implemented using Laravel Cache API., (*9)
Get a List of Objects
Example, (*10)
$objects = $handler->getList('container_name');
Upload an Object
Example, (*11)
$handler->upload('container_name', 'object_name.txt', '/path/to/file/to/upload.txt', 'text/plain');
Download an Object
The method download() will return GuzzleHttp response., (*12)
You can access the file content by getBody() method., (*13)
$response = $handler->download('container_name', 'object_name.txt');
echo $response->getBody();
Or you can make download response as follows., (*14)
$response = $handler->download('container_name', 'object_name.txt');
return reponse($response->getBody())->header('Content-Type', $response->getHeader('Content-Type'));
Delete an Object
Example, (*15)
$handler->delete('container_name', 'object_name.txt');