goodgay/huaweiobs

Object Storage Service (OBS) provides massive, secure, highly reliable, and low-cost data storage capabilities, allowing users to store data of any type and size. It is suitable for various data storage scenarios such as enterprise backup/archiving, video on demand, and video surveillance.

0.9.6 2021-01-13 06:10 UTC

This package is auto-updated.

Last update: 2024-05-13 13:40:15 UTC


README

An easy way to use the official php sdk client in your Laravel or Lumen applications.

Installation and Configuration

Install the current version of the goodgay/huaweiobs package via composer:

composer require goodgay/huaweiobs

Laravel

The package's service provider will automatically register its service provider.

Publish the configuration file:

php artisan vendor:publish --provider="Goodgay\HuaweiOBS\HWOBSServiceProvider"
Alternative configuration method via .env file

After you publish the configuration file as suggested above, you may configure OBS by adding the following to your application's .env file (with appropriate values):

HWOBS_ACCESS_KEY_ID=5RXYW9YKK
HWOBS_SECRET_ACCESS_KEY=NBHXP7UEBqNu
HWOBS_DEFAULT_REGION=region
HWOBS_BUCKET=test
HWOBS_URL=
HWOBS_ENDPOINT=https://obs.cn-south-1.myhuaweicloud.com

Lumen

If you work with Lumen, please register the service provider and configuration in bootstrap/app.php:

$app->register(Goodgay\HuaweiOBS\HWOBSServiceProvider::class);
$app->configure('hwobs');

Manually copy the configuration file to your application.

Usage

The HWobs facade is just an entry point into the php-obs sdk, so previously you might have used:

use ObsV3\ObsClient;
$obsClient = ObsClient::factory ( [
		'key' => $ak,
		'secret' => $sk,
		'endpoint' => $endpoint,
		'socket_timeout' => 30,
		'connect_timeout' => 10
] );

$resp = $obsClient -> listObjects(['Bucket' => $bucketName]);
foreach ( $resp ['Contents'] as $content ) {
    printf("\t%s etag[%s]\n", $content ['Key'], $content ['ETag']);
}
printf("\n");
    

You can now replace those last two lines with simply:

use Goodgay\HuaweiOBS\HWobs;

$return = HWobs::all();

//or

$return = HWobs::obs()->listObjects(['Bucket' => $bucketName]);

Lumen users who wish to use Facades can do so by editing the bootstrap/app.php file to include the following:

$app->withFacades(true,[
     Goodgay\HuaweiOBS\HWobs::class  => 'Hwobs'
]);
// 文件系统的配置文件位于 config/filesystems.php
'hwobs' => [
    'driver'    => 'hwobs',
    'key'       => env('HWOBS_ACCESS_KEY_ID',''),
    'secret'    => env('HWOBS_SECRET_ACCESS_KEY',''),
    'region'    => env('HWOBS_DEFAULT_REGION',''),
    'bucket'    => env('HWOBS_BUCKET',''),
    'url'       => env('HWOBS_URL',''),
    'endpoint'  => env('HWOBS_ENDPOINT',''),
    'exceptionResponseMode'  => false,
],


Storage::disk('hwobs')->put('file.txt', 'Contents');

Advanced Usage

Because the package is a wrapper around the official php-obs sdk, you can do pretty much anything with this package.

To upload:

$resp = HWobs::putText("object-name","some content");
$resp = HWobs::putFile("object-name","./some.txt");

To download:

$resp = HWobs::getText("object-name");
$resp = HWobs::getStream("object-name");
$resp = HWobs::getFile("object-name",'save_path.txt');

To manage objects:

$resp = HWobs::getMetadata("object-name");
$resp = HWobs::delete("object-name");
$resp = HWobs::all();
$resp = HWobs::deleteMulti(['object-name1','object-name2']);

Bugs, Suggestions and Support

Special thanks to Visual Studio Code for their Open Source License Program ... and the excellent IDE, of course!

Please use Github for reporting bugs, and making comments or suggestions.

Copyright and License

laravel-huaweiobs was written by fuzuchang and is released under the MIT License.

Copyright (c) 2020 fuzuchang