12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406 |
- <?php
- /**
- * Copyright 2019 Huawei Technologies Co.,Ltd.
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
- * this file except in compliance with the License. You may obtain a copy of the
- * License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed
- * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations under the License.
- *
- */
- if (file_exists('vendor/autoload.php')) {
- require 'vendor/autoload.php';
- } else {
- require '../vendor/autoload.php'; // sample env
- }
- if (file_exists('obs-autoloader.php')) {
- require 'obs-autoloader.php';
- } else {
- require '../obs-autoloader.php'; // sample env
- }
- use Obs\ObsClient;
- use Obs\ObsException;
- use function GuzzleHttp\json_encode;
- $ak = '*** Provide your Access Key ***';
- $sk = '*** Provide your Secret Key ***';
- $endpoint = 'https://your-endpoint:443';
- $obsClient = ObsClient::factory(array (
- 'key' => $ak,
- 'secret' => $sk,
- 'endpoint' => $endpoint,
- ));
- $obsClient->initLog(array (
- 'FilePath' => './logs',
- 'FileName' => 'eSDK-OBS-PHP.log',
- 'MaxFiles' => 10,
- 'Level' => WARN
- ));
- $bucketName = 'bucket000';
- $objectKey = 'test';
- // create bucket
- function CreateBucket() {
- global $obsClient;
- global $bucketName;
- echo "create bucket start...\n";
- try {
- $resp = $obsClient->createBucket(array (
- 'Bucket' => $bucketName,
- 'ACL' => ObsClient::AclPrivate,
- 'LocationConstraint' => '',
- 'StorageClass' => ObsClient::StorageClassWarm
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("Location:%s\n", $resp ['Location']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // list buckets
- function ListBuckets() {
- global $obsClient;
- echo "list bucket start...\n";
- try {
- $resp = $obsClient->listBuckets();
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- $i = 0;
- foreach ( $resp ['Buckets'] as $bucket ) {
- printf("Buckets[$i][Name]:%s,Buckets[$i][CreationDate]:%s\n", $bucket ['Name'], $bucket ['CreationDate']);
- $i ++;
- }
- printf("Owner[ID]:%s\n", $resp ['Owner'] ['ID']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // delete bucket
- function DeleteBucket() {
- global $obsClient;
- global $bucketName;
- echo "delete bucket start...\n";
- try {
- $resp = $obsClient->deleteBucket(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // list objects
- function ListObjects() {
- global $obsClient;
- global $bucketName;
- echo "list objects start...\n";
- try {
- $resp = $obsClient->listObjects(array (
- 'Bucket' => $bucketName,
- 'Delimiter' => '',
- 'Marker' => '',
- 'MaxKeys' => '',
- 'Prefix' => ''
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("IsTruncated:%d,Marker:%s,NextMarker:%s,Name:%s\n", $resp ['IsTruncated'], $resp ['Marker'], $resp ['NextMarker'], $resp ['Name']);
- printf("Prefix:%s,Delimiter:%s,MaxKeys:%d\n", $resp ['Prefix'], $resp ['Delimiter'], $resp ['MaxKeys']);
- $i = 0;
- foreach ( $resp ['CommonPrefixes'] as $CommonPrefixe ) {
- printf("CommonPrefixes[$i][Prefix]:%s\n", $CommonPrefixe ['Prefix']);
- $i ++;
- }
- $i = 0;
- foreach ( $resp ['Contents'] as $content ) {
- printf("Contents[$i][ETag]:%s,Contents[$i][Size]:%d,Contents[$i][StorageClass]:%s\n", $content ['ETag'], $content ['Size'], $content ['StorageClass']);
- printf("Contents[$i][Key]:%s,Contents[$i][LastModified]:%s\n", $content ['Key'], $content ['LastModified']);
- printf("Contents[$i][Owner][ID]:%s\n", $content ['Owner'] ['ID']);
- $i ++;
- }
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // list versions
- function ListVersions() {
- global $obsClient;
- global $bucketName;
- echo "list versions start...\n";
- try {
- $resp = $obsClient->listVersions(array (
- 'Bucket' => $bucketName,
- 'Delimiter' => '',
- 'KeyMarker' => '',
- 'MaxKeys' => '',
- 'Prefix' => '',
- 'VersionIdMarker' => ''
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("IsTruncated:%d,KeyMarker:%s,VersionIdMarker:%s,NextKeyMarker:%s\n", $resp ['IsTruncated'], $resp ['KeyMarker'], $resp ['VersionIdMarker'], $resp ['NextKeyMarker']);
- printf("NextVersionIdMarker:%s,Name:%s,Prefix:%s,Delimiter:%s,MaxKeys:%s\n", $resp ['NextVersionIdMarker'], $resp ['Name'], $resp ['Prefix'], $resp ['Delimiter'], $resp ['MaxKeys']);
- $i = 0;
- foreach ( $resp ['CommonPrefixes'] as $CommonPrefixe ) {
- printf("CommonPrefixes[$i][Prefix]:%s\n", $CommonPrefixe ['Prefix']);
- $i ++;
- }
- $i = 0;
- foreach ( $resp ['Versions'] as $version ) {
- printf("Versions[$i][ETag]:%s,Versions[$i][Size]:%d,Versions[$i][StorageClass]:%s\n", $version ['ETag'], $version ['Size'], $version ['StorageClass']);
- printf("Versions[$i][Key]:%s,Versions[$i][VersionId]:%s,Versions[$i][IsLatest]:%d,Versions[$i][LastModified]:%s\n", $version ['Key'], $version ['VersionId'], $version ['IsLatest'], $version ['LastModified']);
- printf("Versions[$i][Owner][ID]:%s\n", $version ['Owner'] ['ID']);
- $i ++;
- }
- $i = 0;
- foreach ( $resp ['DeleteMarkers'] as $deleteMarker ) {
- printf("DeleteMarkers[$i][Key]:%s,DeleteMarkers[$i][VersionId]:%s,DeleteMarkers[$i][IsLatest]:%d,DeleteMarkers[$i][LastModified]:%s\n", $deleteMarker ['Key'], $deleteMarker ['VersionId'], $deleteMarker ['IsLatest'], $deleteMarker ['LastModified']);
- printf("DeleteMarkers[$i][Owner][ID]:%s\n", $deleteMarker ['Owner'] ['ID']);
- $i ++;
- }
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // head bucket
- function HeadBucket() {
- global $obsClient;
- global $bucketName;
- echo "head bucket start...\n";
- try {
- $resp = $obsClient->headBucket(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get bucket metadata
- function GetBucketMetadata() {
- global $obsClient;
- global $bucketName;
- echo "get bucket metatdata start...\n";
- try {
- $resp = $obsClient->getBucketMetadata(array (
- "Bucket" => $bucketName,
- "Origin" => "www.example.com",
- "RequestHeader" => "header1"
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("StorageClass:%s\n", $resp ["StorageClass"]);
- printf("AllowOrigin:%s\n", $resp ["AllowOrigin"]);
- printf("MaxAgeSeconds:%s\n", $resp ["MaxAgeSeconds"]);
- printf("ExposeHeader:%s\n", $resp ["ExposeHeader"]);
- printf("AllowHeader:%s\n", $resp ["AllowHeader"]);
- printf("AllowMethod:%s\n", $resp ["AllowMethod"]);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get bucket location
- function GetBucketLocation() {
- global $obsClient;
- global $bucketName;
- echo "get bucket location start...\n";
- try {
- $resp = $obsClient->getBucketLocation(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("Location:%s\n", $resp ['Location']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get bucket storageinfo
- function GetBucketStorageInfo() {
- global $obsClient;
- global $bucketName;
- echo "get bucket storage info start...\n";
- try {
- $resp = $obsClient->getBucketStorageInfo(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("Size:%d,ObjectNumber:%d\n", $resp ['Size'], $resp ['ObjectNumber']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // set bucket quota
- function SetBucketQuota() {
- global $obsClient;
- global $bucketName;
- echo "set bucket quota start...\n";
- try {
- $resp = $obsClient->setBucketQuota(array (
- 'Bucket' => $bucketName,
- 'StorageQuota' => 1048576
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get bucket quota
- function GetBucketQuota() {
- global $obsClient;
- global $bucketName;
- echo "get bucket quota start...\n";
- try {
- $resp = $obsClient->getBucketQuota(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("StorageQuota:%s\n", $resp ['StorageQuota']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // set bucket storage policy
- function SetBucketStoragePolicy() {
- global $obsClient;
- global $bucketName;
- echo "set bucket storage policy start...\n";
- try {
- $resp = $obsClient->setBucketStoragePolicy(array (
- 'Bucket' => $bucketName,
- 'StorageClass' => ObsClient::StorageClassCold
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get bucket storage policy
- function GetBucketStoragePolicy() {
- global $obsClient;
- global $bucketName;
- echo "get bucket storage policy start...\n";
- try {
- $resp = $obsClient->getBucketStoragePolicy(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("StorageClass:%s\n", $resp ['StorageClass']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // set bucket acl
- function SetBucketAcl() {
- global $obsClient;
- global $bucketName;
- echo "set bucket ACL start...\n";
- try {
- $resp = $obsClient->setBucketAcl(array (
- 'Bucket' => $bucketName,
- 'ACL' => '',
- 'Owner' => array (
- 'ID' => 'ownerid'
- ),
- 'Grants' => array (
- 0 => array (
- 'Grantee' => array (
- 'ID' => 'userid'
- ),
- 'Permission' => ObsClient::PermissionRead,
- 'Delivered' => true
- ),
- 1 => array (
- 'Grantee' => array (
- 'URI' => ObsClient::AllUsers
- ),
- 'Permission' => ObsClient::PermissionWrite,
- 'Delivered' => true
- )
- )
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get bucket acl
- function GetBucketAcl() {
- global $obsClient;
- global $bucketName;
- echo "get bucket ACL start...\n";
- try {
- $resp = $obsClient->getBucketAcl(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("Owner[ID]:%s\n", $resp ['Owner'] ['ID'] );
- $i = 0;
- foreach ( $resp ['Grants'] as $grant ) {
- printf("Grants[$i][Grantee][ID]:%s,Grants[$i][Grantee][URI]:%s\n",$grant ['Grantee'] ['ID'], $grant ['Grantee'] ['URI']);
- printf("Grants[$i][Permission]:%s\n", $grant ['Permission']);
- printf("Grants[$i][Delivered]:%s\n", $grant['Delivered'] ? 'true' : 'false');
- $i ++;
- }
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // set bucket logging configuration
- function SetBucketLogging() {
- global $obsClient;
- global $bucketName;
- echo "set bucket logging configuration start...\n";
- try {
- $resp = $obsClient->setBucketLogging(array (
- 'Bucket' => $bucketName,
- 'Agency' => 'your agency',
- 'LoggingEnabled' => array (
- 'TargetBucket' => 'bucket003',
- 'TargetPrefix' => 'bucket.log',
- 'TargetGrants' => array (
- 0 => array (
- 'Grantee' => array (
- 'ID' => 'userid'
- ),
- 'Permission' => ObsClient::PermissionRead
- ),
- 1 => array (
- 'Grantee' => array (
- 'URI' => ObsClient::AllUsers,
- ),
- 'Permission' => ObsClient::PermissionRead
- )
- )
- )
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get bucket logging configuration
- function GetBucketLogging() {
- global $obsClient;
- global $bucketName;
- echo "get bucket logging configuration start...\n";
- try {
- $resp = $obsClient->getBucketLogging(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("Agency:%s\n", $resp ['Agency']);
- printf("LoggingEnabled[TargetBucket]:%s,LoggingEnabled[TargetPrefix]:%s\n", $resp ['LoggingEnabled'] ['TargetBucket'], $resp ['LoggingEnabled'] ['TargetPrefix']);
- if (is_array($resp ['LoggingEnabled'] ['TargetGrants'])) {
- $i = 0;
- foreach ( $resp ['LoggingEnabled'] ['TargetGrants'] as $grant ) {
- printf("LoggingEnabled[$i][TargetGrants][Permission]:%s\n", $grant ['Permission']);
- printf("LoggingEnabled[$i][TargetGrants][Grantee][ID]:%s,LoggingEnabled[$i][TargetGrants][Grantee][URI]:%s\n", $grant ['Grantee'] ['ID'], $grant ['Grantee'] ['URI']);
- $i ++;
- }
- }
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // set bucket policy
- function SetBucketPolicy() {
- global $obsClient;
- global $bucketName;
- echo "set bucket policy start...\n";
- try {
- $resp = $obsClient->setBucketPolicy(array (
- 'Bucket' => $bucketName,
- 'Policy' => 'your policy'
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get bucket policy
- function GetBucketPolicy() {
- global $obsClient;
- global $bucketName;
- echo "get bucket policy start...\n";
- try {
- $resp = $obsClient->getBucketPolicy(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("Policy:%s\n", $resp ['Policy']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // delete bucket policy
- function DeleteBucketPolicy() {
- global $obsClient;
- global $bucketName;
- echo "delete bucket policy start...\n";
- try {
- $resp = $obsClient->deleteBucketPolicy(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // set bucket lifycycle configuration
- function SetBucketLifecycle() {
- global $obsClient;
- global $bucketName;
- echo "set bucket lifecycle configuration start...\n";
- try {
- $resp = $obsClient->setBucketLifecycle(array (
- 'Bucket' => $bucketName,
- 'Rules' => array (
- 0 => array (
- 'ID' => '',
- 'Prefix' => 'ok',
- 'Status' => 'Enabled',
- 'Transitions' => array (
- 0 => array (
- 'StorageClass' => ObsClient::StorageClassWarm,
- 'Date' => '2019-02-01T00:00:00Z'
- ),
- 1 => array (
- 'StorageClass' => ObsClient::StorageClassCold,
- 'Date' => '2019-03-01T00:00:00Z'
- )
- ),
- 'Expiration' => array (
- 'Date' => '2019-04-01T00:00:00Z'
- ),
- 'NoncurrentVersionTransitions' => array (
- 0 => array (
- 'StorageClass' => ObsClient::StorageClassWarm,
- 'NoncurrentDays' => 30
- ),
- 1 => array (
- 'StorageClass' => ObsClient::StorageClassCold,
- 'NoncurrentDays' => 60
- )
- ),
- // 'Expiration'=>array('Days'=>100),
- 'NoncurrentVersionExpiration' => array (
- 'NoncurrentDays' => 60
- )
- )
- )
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get bucket lifycycle configuration
- function GetBucketLifecycle() {
- global $obsClient;
- global $bucketName;
- echo "get bucket lifecycle configuration start...\n";
- try {
- $resp = $obsClient->getBucketLifecycle(array (
- 'Bucket' => $bucketName
- ));
- $i = 0;
- foreach ( $resp ['Rules'] as $rule ) {
- foreach ( $rule ['Transitions'] as $index => $transition ) {
- printf("Rules[$i][Transitions][$index][Date]:%s,Rules[$i][Transitions][$index][StorageClass]:%s\n", $transition ['Date'], $transition ['StorageClass']);
- }
- printf("Rules[$i][Expiration][Date]:%s,Rules[$i][Expiration][Days]:%d\n", $rule ['Expiration'] ['Date'], $rule ['Expiration'] ['Days']);
- printf("Rules[$i][NoncurrentVersionExpiration][NoncurrentDays]:%s\n", $rule ['NoncurrentVersionExpiration'] ['NoncurrentDays']);
- foreach ( $rule ['NoncurrentVersionTransitions'] as $index => $noncurrentVersionTransition ) {
- printf("Rules[$i][NoncurrentVersionTransitions][$index][NoncurrentDays]:%d,Rules[$i][NoncurrentVersionTransitions][$index][StorageClass]:%s\n", $noncurrentVersionTransition ['NoncurrentDays'], $noncurrentVersionTransition ['StorageClass']);
- }
- printf("Rules[$i][ID]:%s,Rules[$i][Prefix]:%s,Rules[$i][Status]:%s\n", $rule ['ID'], $rule ['Prefix'], $rule ['Status']);
- $i ++;
- }
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // delete bucket lifycycle configuration
- function DeleteBucketLifecycle() {
- global $obsClient;
- global $bucketName;
- echo "delete bucket lifecycle configuration start...\n";
- try {
- $resp = $obsClient->deleteBucketLifecycle(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // set bucket website configuration
- function SetBucketWebsite() {
- global $obsClient;
- global $bucketName;
- echo "set bucket website configuration start...\n";
- try {
- $resp = $obsClient->setBucketWebsite(array (
- 'Bucket' => $bucketName,
- // 'RedirectAllRequestsTo'=>array('HostName'=>'obs.hostname','Protocol'=>'http'),
- 'IndexDocument' => array (
- 'Suffix' => 'index.html'
- ),
- 'ErrorDocument' => array (
- 'Key' => 'error.html'
- ),
- 'RoutingRules' => array (
- 0 => array (
- 'Condition' => array (
- 'KeyPrefixEquals' => 'docs/',
- 'HttpErrorCodeReturnedEquals' => 404
- ),
- 'Redirect' => array (
- 'ReplaceKeyPrefixWith' => 'documents/',
- 'HostName' => 'obs.hostname',
- 'Protocol' => 'http',
- 'HttpRedirectCode' => 308
- )
- )
- )
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get bucket website configuration
- function GetBucketWebsite() {
- global $obsClient;
- global $bucketName;
- echo "get bucket website configuration start...\n";
- try {
- $resp = $obsClient->GetBucketWebsite(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("RedirectAllRequestsTo[HostName]:%s,RedirectAllRequestsTo[Protocol]:%s\n", $resp ['RedirectAllRequestsTo'] ['HostName'], $resp ['RedirectAllRequestsTo'] ['Protocol']);
- printf("IndexDocument[Suffix]:%s\n", $resp ['IndexDocument'] ['Suffix']);
- printf("ErrorDocument[Key]:%s\n", $resp ['ErrorDocument'] ['Key']);
- $i = 0;
- foreach ( $resp ['RoutingRules'] as $rout ) {
- printf("RoutingRules[$i][Condition][HttpErrorCodeReturnedEquals]:%s,RoutingRules[$i][Condition][KeyPrefixEquals]:%s\n", $rout ['Condition'] ['HttpErrorCodeReturnedEquals'], $rout ['Condition'] ['KeyPrefixEquals']);
- printf("RoutingRules[$i][Redirect][Protocol]:%s,RoutingRules[$i][Redirect][HostName]:%s,RoutingRules[$i][Redirect][ReplaceKeyPrefixWith]:%s,RoutingRules[$i][Redirect][ReplaceKeyWith]:%s,RoutingRules[$i][Redirect][HttpRedirectCode]:%s\n", $rout ['Redirect'] ['Protocol'], $rout ['Redirect'] ['HostName'], $rout ['Redirect'] ['ReplaceKeyPrefixWith'], $rout ['Redirect'] ['ReplaceKeyWith'], $rout ['Redirect'] ['HttpRedirectCode']);
- $i ++;
- }
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // delete bucket website configuration
- function DeleteBucketWebsite() {
- global $obsClient;
- global $bucketName;
- echo "delete bucket website configuration start...\n";
- try {
- $resp = $obsClient->deleteBucketWebsite(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // set bucket versioning configuration
- function SetBucketVersioning() {
- global $obsClient;
- global $bucketName;
- echo "set bucket versioning configuration start...\n";
- try {
- $resp = $obsClient->setBucketVersioning(array (
- 'Bucket' => $bucketName,
- 'Status' => 'Suspended'
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get bucket versioning configuration
- function GetBucketVersioning() {
- global $obsClient;
- global $bucketName;
- echo "get bucket versioning configuration start...\n";
- try {
- $resp = $obsClient->getBucketVersioning(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("Status:%s\n", $resp ['Status']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // set bucket cors
- function SetBucketCors() {
- global $obsClient;
- global $bucketName;
- echo "set bucket cors start...\n";
- try {
- $resp = $obsClient->setBucketCors(array (
- 'Bucket' => $bucketName,
- 'CorsRules' => array (
- 0 => array (
- 'ID' => '123456',
- 'AllowedMethod' => array (
- 0 => "PUT",
- 1 => "POST",
- 2 => "GET",
- 3 => "DELETE"
- ),
- 'AllowedOrigin' => array (
- 0 => "obs.hostname1"
- ),
- 'AllowedHeader' => array (
- 0 => "header-1",
- 1 => "header-2"
- )
- )
- )
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // delete bucket cors
- function DeleteBucketCors() {
- global $obsClient;
- global $bucketName;
- echo "delete bucket cors start...\n";
- try {
- $resp = $obsClient->deleteBucketCors(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get bucket cors
- function GetBucketCors() {
- global $obsClient;
- global $bucketName;
- echo "get bucket cors start...\n";
- try {
- $resp = $obsClient->getBucketCors(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- print_r($resp ['CorsRules']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // options bucket
- function OptionsBucket() {
- global $obsClient;
- global $bucketName;
- echo "options bucket start...\n";
- try {
- $resp = $obsClient->optionsBucket(array (
- 'Bucket' => $bucketName,
- 'Origin' => 'obs.hostname1',
- 'AccessControlRequestMethods' => array (
- 0 => "PUT",
- 1 => "POST"
- ),
- 'AccessControlRequestHeaders' => array (
- 0 => "header-1",
- 1 => "header-2"
- )
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- print_r($resp);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // set bucket tagging
- function SetBucketTagging() {
- global $obsClient;
- global $bucketName;
- echo "set bucket tagging start...\n";
- try {
- $resp = $obsClient->setBucketTagging(array (
- 'Bucket' => $bucketName,
- 'Tags' => array (
- 0 => array (
- 'Key' => 'testKey1',
- 'Value' => 'testValue1'
- ),
- 1 => array (
- 'Key' => 'testKey2',
- 'Value' => 'testValue2'
- )
- )
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ["RequestId"]);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get bucket tagging
- function GetBucketTagging() {
- global $obsClient;
- global $bucketName;
- echo "get bucket tagging start...\n";
- try {
- $resp = $obsClient->getBucketTagging(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ["RequestId"]);
- foreach ( $resp ["Tags"] as $tag ) {
- printf("Tag[%s:%s]\n", $tag ["Key"], $tag ["Value"]);
- }
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // delete bucket tagging
- function DeleteBucketTagging() {
- global $obsClient;
- global $bucketName;
- echo "delete bucket tagging start...\n";
- try {
- $resp = $obsClient->deleteBucketTagging(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ["RequestId"]);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // set bucket notification
- function SetBucketNotification() {
- global $obsClient;
- global $bucketName;
- echo "set bucket notification start...\n";
- try {
- $resp = $obsClient->setBucketNotification(array (
- 'Bucket' => $bucketName,
- 'TopicConfigurations' => array (
- 0 => array (
- 'ID' => '001',
- 'Topic' => 'your topic',
- 'Event' => array (
- 0 => 'ObjectCreated:*'
- ),
- 'Filter' => array (
- 0 => array (
- 'Name' => 'prefix',
- 'Value' => 'smn/'
- ),
- 1 => array (
- 'Name' => 'suffix',
- 'Value' => '.jpg'
- )
- )
- )
- )
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ["RequestId"]);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get bucket notification
- function GetBucketNotification() {
- global $obsClient;
- global $bucketName;
- echo "get bucket notification start...\n";
- try {
- $resp = $obsClient->getBucketNotification(array (
- 'Bucket' => $bucketName
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ["RequestId"]);
- print_r($resp ['TopicConfigurations']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // delete object
- function DeleteObject() {
- global $obsClient;
- global $bucketName;
- global $objectKey;
- echo "delete object start...\n";
- try {
- $resp = $obsClient->deleteObject(array (
- 'Bucket' => $bucketName,
- 'Key' => $objectKey,
- 'VersionId' => ''
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("DeleteMarker:%s,VersionId:%s\n", $resp ['DeleteMarker'], $resp ['VersionId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // options object
- function OptionsObject() {
- global $obsClient;
- global $bucketName;
- global $objectKey;
- echo "options bucket start...\n";
- try {
- $resp = $obsClient->optionsObject(array (
- 'Bucket' => $bucketName,
- 'Key' => $objectKey,
- 'Origin' => 'obs.hostname1',
- 'AccessControlRequestMethods' => array (
- "PUT",
- "GET"
- ),
- 'AccessControlRequestHeaders' => array (
- 0 => "header-1",
- 1 => "header-2"
- )
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- print_r($resp);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // delete objects
- function DeleteObjects() {
- global $obsClient;
- global $bucketName;
- echo "delete objects start...\n";
- try {
- $resp = $obsClient->deleteObjects(array (
- 'Bucket' => $bucketName,
- 'Objects' => array (
- 0 => array (
- 'Key' => 'test'
- ),
- 1 => array (
- 'Key' => 'file.log'
- )
- ),
- 'Quiet' => false
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- $i = 0;
- foreach ( $resp ['Errors'] as $error ) {
- printf("Errors[$i][Key]:%s,Errors[$i][VersionId]:%s锛孍rrors[$i][Code]:%s锛孍rrors[$i][Message]:%s\n", $error ['Key'], $error ['VersionId'], $error ['Code'], $error ['Message']);
- $i ++;
- }
- $i = 0;
- foreach ( $resp ['Deleteds'] as $delete ) {
- printf("Deleteds[$i][Key]:%s,Deleted[$i][VersionId]:%s锛孌eleted[$i][DeleteMarker]:%s锛孌eleted[$i][DeleteMarkerVersionId]:%s\n", $delete ['Key'], $delete ['VersionId'], $delete ['DeleteMarker'], $delete ['DeleteMarkerVersionId']);
- $i ++;
- }
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // set object acl
- function SetObjectAcl() {
- global $obsClient;
- global $bucketName;
- global $objectKey;
- echo "set object ACL start...\n";
- try {
- $resp = $obsClient->setObjectAcl(array (
- 'Bucket' => $bucketName,
- 'Key' => $objectKey,
- 'Delivered' => true,
- 'Grants' => array (
- 0 => array (
- 'Grantee' => array (
- 'ID' => 'userid',
- ),
- 'Permission' => ObsClient::PermissionWrite
- ),
- 1 => array (
- 'Grantee' => array (
- 'URI' => ObsClient::AllUsers
- ),
- 'Permission' => ObsClient::PermissionRead
- )
- ),
- 'Owner' => array (
- 'ID' => 'ownerid'
- )
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get object acl
- function GetObjectAcl() {
- global $obsClient;
- global $bucketName;
- global $objectKey;
- echo "get bucket ACL start...\n";
- try {
- $resp = $obsClient->getObjectAcl(array (
- 'Bucket' => $bucketName,
- 'Key' => $objectKey
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("Owner[ID]:%s\n", $resp ['Owner'] ['ID']);
- printf("Delivered:%s\n", $resp['Delivered'] ? 'true' : 'false');
- $i = 0;
- foreach ( $resp ['Grants'] as $grant ) {
- printf("Grants[$i][Grantee][ID]:%s,Grants[$i][Grantee][URI]:%s\n", $grant ['Grantee'] ['ID'], $grant ['Grantee'] ['URI']);
- printf("Grants[$i][Permission]:%s\n", $grant ['Permission']);
- $i ++;
- }
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // restore object
- function RestoreObject() {
- global $obsClient;
- global $bucketName;
- global $objectKey;
- echo "restore object start...\n";
- try {
- $resp = $obsClient->restoreObject(array (
- "Bucket" => $bucketName,
- "Key" => $objectKey,
- "VersionId" => NULL,
- "Days" => 1,
- "Tier" => ObsClient::RestoreTierExpedited
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ["RequestId"]);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // put object
- function PutObject() {
- global $obsClient;
- global $bucketName;
- global $objectKey;
- echo "put object start...\n";
- try {
- $resp = $obsClient->putObject(array (
- 'Bucket' => $bucketName,
- 'Key' => $objectKey,
- 'Metadata' => array (
- 'test' => "value"
- ),
- // 'Body'=>'msg to put',
- 'ContentType' => 'text/plain',
- 'SourceFile' => '/temp/test.txt'
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("ETag:%s,VersionId:%s\n", $resp ['ETag'], $resp ['VersionId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get object metadata
- function GetObjectMetadata() {
- global $obsClient;
- global $bucketName;
- global $objectKey;
- echo "get object metadata start...\n";
- try {
- $resp = $obsClient->getObjectMetadata(array (
- 'Bucket' => $bucketName,
- 'Key' => $objectKey
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("Expiration:%s,LastModified:%s,ContentLength:%d,StorageClass:%s\n", $resp ['Expiration'], $resp ['LastModified'], $resp ['ContentLength'], $resp ['StorageClass']);
- printf("ETag:%s,VersionId:%s,WebsiteRedirectLocation:%s\n", $resp ['ETag'], $resp ['VersionId'], $resp ['WebsiteRedirectLocation']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // get object
- function GetObject() {
- global $obsClient;
- global $bucketName;
- global $objectKey;
- echo "get object start...\n";
- try {
- $resp = $obsClient->getObject(array (
- 'Bucket' => $bucketName,
- 'Key' => $objectKey,
- 'Range' => 'bytes=0-10',
- 'SaveAsFile' => '/temp/test.txt'
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("Metadata:%s\n", json_encode($resp ['Metadata']));
- printf("DeleteMarker:%s,Expiration:%s,LastModified:%s\n", $resp ['DeleteMarker'], $resp ['Expiration'], $resp ['LastModified']);
- printf("ContentLength:%d,ETag:%s,VersionId:%s,SaveAsFile:%s\n", $resp ['ContentLength'], $resp ['ETag'], $resp ['VersionId'], $resp ['SaveAsFile']);
- printf("Expires:%s,WebsiteRedirectLocation:%s\n", $resp ['Expires'], $resp ['WebsiteRedirectLocation']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // copy object
- function CopyObject() {
- global $obsClient;
- global $bucketName;
- global $objectKey;
- echo "copy object start...\n";
- try {
- $resp = $obsClient->copyObject(array (
- 'Bucket' => $bucketName,
- 'Key' => $objectKey,
- 'CopySource' => 'bucket003/test',
- 'Metadata' => array (
- 'test' => "value"
- )
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("ETag:%s,VersionId:%s,LastModified:%s,CopySourceVersionId:%s\n", $resp ['ETag'], $resp ['VersionId'], $resp ['LastModified'], $resp ['CopySourceVersionId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // initiate multipart upload
- function InitiateMultipartUpload() {
- global $obsClient;
- global $bucketName;
- global $objectKey;
- echo "initiate mutipart upload start...\n";
- try {
- $resp = $obsClient->initiateMultipartUpload(array (
- 'Bucket' => $bucketName,
- 'Key' => $objectKey
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("Bucket:%s,Key:%s,UploadId:%s\n", $resp ['Bucket'], $resp ['Key'], $resp ['UploadId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // abort multipart upload
- function AbortMultipartUpload() {
- global $obsClient;
- global $bucketName;
- global $objectKey;
- echo "abort mutipart upload start...\n";
- try {
- $resp = $obsClient->abortMultipartUpload(array (
- 'Bucket' => $bucketName,
- 'Key' => $objectKey,
- 'UploadId' => 'uploadid'
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // list multipart uploads
- function ListMultipartUploads() {
- global $obsClient;
- global $bucketName;
- echo "list mutipart upload start...\n";
- try {
- $resp = $obsClient->listMultipartUploads(array (
- 'Bucket' => $bucketName,
- 'MaxUploads' => 1000
- ));
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("Bucket锛�%s,KeyMarker:%s,UploadIdMarker:%s,NextKeyMarker:%s\n", $resp ['Bucket'], $resp ['KeyMarker'], $resp ['UploadIdMarker'], $resp ['NextKeyMarker']);
- printf("Prefix:%s,Delimiter:%s,NextUploadIdMarker:%s,MaxUploads:%d,IsTruncated:%s\n", $resp ['Prefix'], $resp ['Delimiter'], $resp ['NextUploadIdMarker'], $resp ['MaxUploads'], $resp ['IsTruncated']);
- $i = 0;
- foreach ( $resp ['CommonPrefixes'] as $common ) {
- printf("CommonPrefixes[$i][Prefix]:%s\n", $common ['Prefix']);
- $i ++;
- }
- $i = 0;
- foreach ( $resp ['Uploads'] as $upload ) {
- printf("Uploads[$i][Key]:%s,Uploads[$i][UploadId]:%s,Uploads[$i][StorageClass]:%s,Uploads[$i][Initiated]:%s\n", $upload ['Key'], $upload ['UploadId'], $upload ['StorageClass'], $upload ['Initiated']);
- printf("Uploads[$i][Initiator][ID]:%s,Uploads[$i][Initiator][DisplayName]:%s\n", $upload ['Initiator'] ['ID'], $upload ['Initiator'] ['DisplayName']);
- printf("Uploads[$i][Owner][ID]:%s,Uploads[$i][Owner][DisplayName]:%s\n", $upload ['Owner'] ['ID'], $upload ['Owner'] ['DisplayName']);
- $i ++;
- }
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // upload part
- function UploadPart() {
- global $obsClient;
- global $bucketName;
- global $objectKey;
- echo "upload part start...\n";
- try {
- $resp = $obsClient->uploadPart(array (
- 'Bucket' => $bucketName,
- 'Key' => $objectKey,
- 'UploadId' => 'uploadid',
- 'PartNumber' => 1,
- // 'Body' => 'test',
- 'SourceFile' => '/temp/test.txt'
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("ETag:%s\n", $resp ['ETag']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // copry part
- function CopyPart() {
- global $obsClient;
- global $bucketName;
- global $objectKey;
- echo "copy part start...\n";
- try {
- $resp = $obsClient->copyPart(array (
- 'Bucket' => $bucketName,
- 'Key' => $objectKey,
- 'UploadId' => 'uploadid',
- 'PartNumber' => 1,
- 'CopySource' => 'bucket003/test'
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("ETag:%s,LastModified:%s\n", $resp ['ETag'], $resp ['LastModified']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // list parts
- function ListParts() {
- global $obsClient;
- global $bucketName;
- global $objectKey;
- echo "list parts start...\n";
- try {
- $resp = $obsClient->listParts(array (
- 'Bucket' => $bucketName,
- 'Key' => $objectKey,
- 'UploadId' => 'uploadid',
- 'MaxParts' => 500,
- 'PartNumberMarker' => 0
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("Bucket锛�%s,Key:%s,UploadId:%s,PartNumberMarker:%d\n", $resp ['Bucket'], $resp ['Key'], $resp ['UploadId'], $resp ['PartNumberMarker']);
- printf("NextPartNumberMarker:%d,MaxParts:%d,IsTruncated:%d,StorageClass:%s\n", $resp ['NextPartNumberMarker'], $resp ['MaxParts'], $resp ['IsTruncated'], $resp ['StorageClass']);
- printf("Initiator[ID]:%s,Initiator[DisplayName]:%s\n", $resp ['Initiator'] ['ID'], $resp ['Initiator'] ['DisplayName']);
- printf("Owner[ID]:%s,Owner[DisplayName]:%s\n", $resp ['Owner'] ['ID'], $resp ['Owner'] ['DisplayName']);
- $i = 0;
- foreach ( $resp ['Parts'] as $part ) {
- printf("Parts[$i][PartNumber]:%s,Parts[$i][LastModified]:%s,Parts[$i][ETag]:%s,Parts[$i][Size]:%d\n", $part ['PartNumber'], $part ['LastModified'], $part ['ETag'], $part ['Size']);
- $i ++;
- }
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- // merge parts
- function CompleteMultipartUpload() {
- global $obsClient;
- global $bucketName;
- global $objectKey;
- echo "complete multipart upload start...\n";
- try {
- $resp = $obsClient->completeMultipartUpload(array (
- 'Bucket' => $bucketName,
- 'Key' => $objectKey,
- 'UploadId' => 'uploadid',
- 'Parts' => array (
- 0 => array (
- 'PartNumber' => 1,
- 'ETag' => 'etagvalue'
- )
- )
- ));
- printf("HttpStatusCode:%s\n", $resp ['HttpStatusCode']);
- printf("RequestId:%s\n", $resp ['RequestId']);
- printf("Bucket:%s,Key:%s,ETag:%s,VersionId:%s,Location:%s\n", $resp ['Bucket'], $resp ['Key'], $resp ['ETag'], $resp ['VersionId'], $resp ['Location']);
- } catch ( ObsException $e ) {
- echo $e;
- }
- }
- //----bucket related apis---
- // CreateBucket();
- // ListBuckets();
- // DeleteBucket();
- // ListObjects();
- // ListVersions();
- // HeadBucket();
- // GetBucketMetadata();
- // GetBucketLocation();
- // GetBucketStorageInfo();
- // SetBucketQuota();
- // GetBucketQuota();
- // SetBucketStoragePolicy();
- // GetBucketStoragePolicy();
- // SetBucketAcl();
- // GetBucketAcl();
- // SetBucketLogging();
- // GetBucketLogging();
- // SetBucketPolicy();
- // GetBucketPolicy();
- // DeleteBucketPolicy();
- // SetBucketLifecycle();
- // GetBucketLifecycle();
- // DeleteBucketLifecycle();
- // SetBucketWebsite();
- // GetBucketWebsite();
- // DeleteBucketWebsite();
- // SetBucketVersioning();
- // GetBucketVersioning();
- // SetBucketCors();
- // GetBucketCors();
- // DeleteBucketCors();
- // OptionsBucket();
- // SetBucketTagging();
- // GetBucketTagging();
- // DeleteBucketTagging();
- // SetBucketNotification();
- // GetBucketNotification();
- //-----object related apis--------
- // DeleteObject();
- // OptionsObject();
- // SetObjectAcl();
- // GetObjectAcl();
- // RestoreObject();
- // DeleteObjects();
- // PutObject();
- // GetObject();
- // CopyObject();
- // GetObjectMetadata();
- // InitiateMultipartUpload();
- // ListMultipartUploads();
- // AbortMultipartUpload();
- // UploadPart();
- // ListParts();
- // CompleteMultipartUpload();
- // CopyPart();
|