okashoi / laravel5-conoha-object-handler by okashoi

An object handler for the Conoha Object Storage on Laravel 5.
146
4
1
Package Data
Maintainer Username: okashoi
Maintainer Contact: okashoicircus0@gmail.com (Okada Shohei)
Package Create Date: 2016-11-19
Package Last Update: 2016-12-19
Language: PHP
License: MIT
Last Refreshed: 2024-04-30 15:06:52
Package Statistics
Total Downloads: 146
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 4
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Laravel 5 Conoha Object Handler

CircleCI

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');