An easy way to use the official php sdk client in your Laravel or Lumen applications.
- Installation and Configuration
- Usage
- Advanced Usage
- Bugs, Suggestions and Support
- Copyright and License
Install the current version of the goodgay/huaweiobs
package via composer:
composer require goodgay/huaweiobs
The package's service provider will automatically register its service provider.
Publish the configuration file:
php artisan vendor:publish --provider="Goodgay\HuaweiOBS\HWOBSServiceProvider"
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
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.
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');
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']);
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.
laravel-huaweiobs was written by fuzuchang and is released under the MIT License.
Copyright (c) 2020 fuzuchang