PHP code example of goodgay / huaweiobs

1. Go to this page and download the library: Download goodgay/huaweiobs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

goodgay / huaweiobs example snippets


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



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

use Goodgay\HuaweiOBS\HWobs;

$return = HWobs::all();

//or

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

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


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

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

$resp = HWobs::getMetadata("object-name");
$resp = HWobs::delete("object-name");
$resp = HWobs::all();
$resp = HWobs::deleteMulti(['object-name1','object-name2']);
sh
php artisan vendor:publish --provider="Goodgay\HuaweiOBS\HWOBSServiceProvider"