定制 goodgay/huaweiobs 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

goodgay/huaweiobs

最新稳定版本:0.9.6

Composer 安装命令:

composer require 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.

README 文档

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

统计信息

  • 总下载量: 3.4k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-09