Skip to content

Commit 0860c60

Browse files
okashoiShohei Okada
authored andcommitted
Create README.md
1 parent eb86f22 commit 0860c60

File tree

2 files changed

+105
-2
lines changed

2 files changed

+105
-2
lines changed

README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Laravel 5 Conoha Object Handler
2+
3+
Laravel 5 Package to use [Conoha](https://www.conoha.jp/en/) Object Storage.
4+
5+
## Installation
6+
7+
Install the package via [Composer](http://getcomposer.org).
8+
9+
```sh
10+
composer require okashoi/laravel5-conoha-object-handler
11+
```
12+
13+
To use the package, register the service provider in `config/app.php`.
14+
15+
```php
16+
'providers' => [
17+
// ...
18+
Okashoi\Laravel5ConohaObjectHandler\ConohaObjectServiceProvider::class,
19+
]
20+
```
21+
22+
To configure your connection settings, execute the following command.
23+
24+
```sh
25+
php artisan vendor:publish --provider="Okashoi\Laravel5ConohaObjectHandler\ConohaObjectServiceProvider"
26+
```
27+
28+
Then set the following environment variables in `.env` file.
29+
30+
```
31+
CONOHA_TENANT_ID
32+
CONOHA_USERNAME
33+
CONOHA_PASSWORD
34+
```
35+
36+
## Usage
37+
38+
### Create the Instance
39+
40+
First of all you have to create an `ObjectHandler` instance.
41+
42+
```php
43+
use Okashoi\Laravel5ConohaObjectHandler\ObjectHandler;
44+
45+
$handler = new ObjectHandler();
46+
```
47+
48+
Optionally, you can cache the auth token by specifying the cache key.
49+
(It is recommended. By default, the instance gets a new auth token per a request.)
50+
51+
```php
52+
use Okashoi\Laravel5ConohaObjectHandler\ObjectHandler;
53+
54+
// cache the auth token with key 'conoha_token'
55+
$handler = new ObjectHandler('conoha_token');
56+
```
57+
58+
Caching is implemented using [Laravel Cache API](https://laravel.com/docs/5.3/cache).
59+
60+
### Get a List of Objects
61+
62+
Example
63+
64+
```php
65+
$objects = $handler->getList('container_name');
66+
```
67+
68+
69+
### Upload an Object
70+
71+
Example
72+
73+
```php
74+
$handler->upload('container_name', 'object_name.txt', '/path/to/file/to/upload.txt', 'text/plain');
75+
```
76+
77+
### Download an Object
78+
79+
The method `download()` will return [GuzzleHttp](http://docs.guzzlephp.org/en/latest/) response.
80+
81+
You can access the file content by `getBody()` method.
82+
83+
```php
84+
$response = $handler->download('container_name', 'object_name.txt');
85+
86+
echo $response->getBody();
87+
```
88+
89+
Or you can make download response as follows.
90+
91+
```php
92+
$response = $handler->download('container_name', 'object_name.txt');
93+
94+
return reponse($response->getBody())->header('Content-Type', $response->getHeader('Content-Type'));
95+
```
96+
97+
### Delete an Object
98+
99+
Example
100+
101+
```php
102+
$handler->delete('container_name', 'object_name.txt');
103+
```

src/Okashoi/Laravel5ConohaObjectHandler/config/conoha.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
'tenant_id' => env('CONOHA_TENANT_ID'),
55
'username' => env('CONOHA_USERNAME'),
66
'password' => env('CONOHA_PASSWORD'),
7-
'base_uri' => env('CONOHA_BASE_URI'),
8-
'auth_endpoint' => env('CONOHA_AUTH_ENDPOINT'),
7+
'base_uri' => env('CONOHA_BASE_URI', 'https://object-storage.tyo1.conoha.io/v1/'),
8+
'auth_endpoint' => env('CONOHA_AUTH_ENDPOINT', 'https://identity.tyo1.conoha.io/v2.0/tokens'),
99
];

0 commit comments

Comments
 (0)