123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- if (file_exists ( 'vendor/autoload.php' )) {
- require 'vendor/autoload.php';
- } else {
- require '../vendor/autoload.php';
- }
- if (file_exists ( 'obs-autoloader.php' )) {
- require 'obs-autoloader.php';
- } else {
- require '../obs-autoloader.php';
- }
- use Obs\ObsClient;
- use Obs\ObsException;
- $ak = '*** Provide your Access Key ***';
- $sk = '*** Provide your Secret Key ***';
- $endpoint = 'https://your-endpoint:443';
- $bucketName = 'my-obs-bucket-demo';
- $objectKey = 'my-obs-object-key-demo';
- $obsClient = ObsClient::factory ( [
- 'key' => $ak,
- 'secret' => $sk,
- 'endpoint' => $endpoint,
- 'socket_timeout' => 30,
- 'connect_timeout' => 10
- ] );
- try
- {
-
- echo "Create a new bucket for demo\n\n";
- $obsClient -> createBucket(['Bucket' => $bucketName]);
-
-
-
- $keySuffixWithSlash = "MyObjectKey1/";
- $obsClient -> putObject(['Bucket' => $bucketName, 'Key' => $keySuffixWithSlash]);
- echo "Creating an empty folder " . $keySuffixWithSlash . "\n\n";
-
-
- $resp = $obsClient -> getObject(['Bucket' => $bucketName, 'Key' => $keySuffixWithSlash]);
-
- echo "Size of the empty folder '" . $keySuffixWithSlash. "' is " . $resp['ContentLength'] . "\n\n";
- if($resp['Body']){
- $resp['Body'] -> close();
- }
-
-
- $obsClient -> putObject(['Bucket' => $bucketName, 'Key' => $keySuffixWithSlash . $objectKey, 'Body' => 'Hello OBS']);
- } catch ( ObsException $e ) {
- echo 'Response Code:' . $e->getStatusCode () . PHP_EOL;
- echo 'Error Message:' . $e->getExceptionMessage () . PHP_EOL;
- echo 'Error Code:' . $e->getExceptionCode () . PHP_EOL;
- echo 'Request ID:' . $e->getRequestId () . PHP_EOL;
- echo 'Exception Type:' . $e->getExceptionType () . PHP_EOL;
- } finally{
- $obsClient->close ();
- }
|