okashoi / laravel5-conoha-object-handler
An object handler for the Conoha Object Storage on Laravel 5.
Requires
- guzzlehttp/guzzle: ^6.2
- illuminate/support: ^5.2
Requires (Dev)
- laravel/framework: ^5.2
This package is not auto-updated.
Last update: 2025-01-04 22:13:45 UTC
README
Laravel 5 Package to use Conoha Object Storage.
Installation
Install the package via Composer.
composer require okashoi/laravel5-conoha-object-handler
To use the package, register the service provider in config/app.php
.
'providers' => [ // ... Okashoi\Laravel5ConohaObjectHandler\ConohaObjectServiceProvider::class, ]
To configure your connection settings, execute the following command.
php artisan vendor:publish --provider="Okashoi\Laravel5ConohaObjectHandler\ConohaObjectServiceProvider"
Then set the following environment variables in .env
file.
CONOHA_TENANT_ID
CONOHA_USERNAME
CONOHA_PASSWORD
Usage
Create the Instance
First of all you have to create an ObjectHandler
instance.
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.)
use Okashoi\Laravel5ConohaObjectHandler\ObjectHandler; // cache the auth token with key 'conoha_token' $handler = new ObjectHandler('conoha_token');
Caching is implemented using Laravel Cache API.
Get a List of Objects
Example
$objects = $handler->getList('container_name');
Upload an Object
Example
$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.
You can access the file content by getBody()
method.
$response = $handler->download('container_name', 'object_name.txt'); echo $response->getBody();
Or you can make download response as follows.
$response = $handler->download('container_name', 'object_name.txt'); return reponse($response->getBody())->header('Content-Type', $response->getHeader('Content-Type'));
Delete an Object
Example
$handler->delete('container_name', 'object_name.txt');