OssClient.php 139 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787
  1. <?php
  2. namespace OSS;
  3. use OSS\Core\MimeTypes;
  4. use OSS\Core\OssException;
  5. use OSS\Credentials\Credentials;
  6. use OSS\Credentials\CredentialsProvider;
  7. use OSS\Credentials\StaticCredentialsProvider;
  8. use OSS\Http\RequestCore;
  9. use OSS\Http\RequestCore_Exception;
  10. use OSS\Http\ResponseCore;
  11. use OSS\Model\BucketInfo;
  12. use OSS\Model\CorsConfig;
  13. use OSS\Model\CnameConfig;
  14. use OSS\Model\GetLiveChannelHistory;
  15. use OSS\Model\GetLiveChannelInfo;
  16. use OSS\Model\GetLiveChannelStatus;
  17. use OSS\Model\LoggingConfig;
  18. use OSS\Model\LiveChannelConfig;
  19. use OSS\Model\LiveChannelInfo;
  20. use OSS\Model\LiveChannelListInfo;
  21. use OSS\Model\ObjectListInfoV2;
  22. use OSS\Model\StorageCapacityConfig;
  23. use OSS\Result\AclResult;
  24. use OSS\Result\BodyResult;
  25. use OSS\Result\GetCorsResult;
  26. use OSS\Result\GetLifecycleResult;
  27. use OSS\Result\GetLocationResult;
  28. use OSS\Result\GetLoggingResult;
  29. use OSS\Result\GetRefererResult;
  30. use OSS\Result\GetStorageCapacityResult;
  31. use OSS\Result\GetWebsiteResult;
  32. use OSS\Result\GetCnameResult;
  33. use OSS\Result\HeaderResult;
  34. use OSS\Result\InitiateMultipartUploadResult;
  35. use OSS\Result\ListBucketsResult;
  36. use OSS\Result\ListMultipartUploadResult;
  37. use OSS\Model\ListMultipartUploadInfo;
  38. use OSS\Result\ListObjectsResult;
  39. use OSS\Result\ListObjectsV2Result;
  40. use OSS\Result\ListPartsResult;
  41. use OSS\Result\PutSetDeleteResult;
  42. use OSS\Result\DeleteObjectsResult;
  43. use OSS\Result\CopyObjectResult;
  44. use OSS\Result\CallbackResult;
  45. use OSS\Result\ExistResult;
  46. use OSS\Result\PutLiveChannelResult;
  47. use OSS\Result\GetLiveChannelHistoryResult;
  48. use OSS\Result\GetLiveChannelInfoResult;
  49. use OSS\Result\GetLiveChannelStatusResult;
  50. use OSS\Result\ListLiveChannelResult;
  51. use OSS\Result\AppendResult;
  52. use OSS\Model\ObjectListInfo;
  53. use OSS\Result\SymlinkResult;
  54. use OSS\Result\UploadPartResult;
  55. use OSS\Model\BucketListInfo;
  56. use OSS\Model\LifecycleConfig;
  57. use OSS\Model\RefererConfig;
  58. use OSS\Model\WebsiteConfig;
  59. use OSS\Core\OssUtil;
  60. use OSS\Model\ListPartsInfo;
  61. use OSS\Result\GetBucketInfoResult;
  62. use OSS\Model\BucketStat;
  63. use OSS\Result\GetBucketStatResult;
  64. use OSS\Model\ServerSideEncryptionConfig;
  65. use OSS\Result\GetBucketEncryptionResult;
  66. use OSS\Model\RequestPaymentConfig;
  67. use OSS\Result\GetBucketRequestPaymentResult;
  68. use OSS\Model\Tag;
  69. use OSS\Model\TaggingConfig;
  70. use OSS\Result\GetBucketTagsResult;
  71. use OSS\Model\VersioningConfig;
  72. use OSS\Result\GetBucketVersioningResult;
  73. use OSS\Model\InitiateWormConfig;
  74. use OSS\Result\InitiateBucketWormResult;
  75. use OSS\Model\ExtendWormConfig;
  76. use OSS\Result\GetBucketWormResult;
  77. use OSS\Model\RestoreConfig;
  78. use OSS\Model\ObjectVersionListInfo;
  79. use OSS\Result\ListObjectVersionsResult;
  80. use OSS\Model\DeleteObjectInfo;
  81. use OSS\Model\DeletedObjectInfo;
  82. use OSS\Result\DeleteObjectVersionsResult;
  83. use OSS\Model\TransferAccelerationConfig;
  84. use OSS\Result\GetBucketTransferAccelerationResult;
  85. use OSS\Model\CnameTokenInfo;
  86. use OSS\Result\CreateBucketCnameTokenResult;
  87. use OSS\Result\GetBucketCnameTokenResult;
  88. use OSS\Signer\SignerInterface;
  89. use OSS\Signer\SignerV1;
  90. use OSS\Signer\SignerV4;
  91. /**
  92. * Class OssClient
  93. *
  94. * Object Storage Service(OSS)'s client class, which wraps all OSS APIs user could call to talk to OSS.
  95. * Users could do operations on bucket, object, including MultipartUpload or setting ACL via an OSSClient instance.
  96. * For more details, please check out the OSS API document:https://www.alibabacloud.com/help/doc-detail/31947.htm
  97. */
  98. class OssClient
  99. {
  100. /**
  101. * OssClient constructor.
  102. */
  103. public function __construct()
  104. {
  105. $argNum = func_num_args();
  106. $args = func_get_args();
  107. if ($argNum == 1 && is_array($args[0])) {
  108. call_user_func_array(array($this, '__initNewClient'), $args);
  109. } else {
  110. call_user_func_array(array($this, '__initClient'), $args);
  111. }
  112. }
  113. /**
  114. * There're a few different ways to create an OssClient object:
  115. * 1. Most common one from access Id, access Key and the endpoint: $ossClient = new OssClient($id, $key, $endpoint)
  116. * 2. If the endpoint is the CName (such as www.testoss.com, make sure it's CName binded in the OSS console),
  117. * uses $ossClient = new OssClient($id, $key, $endpoint, true)
  118. * 3. If using Alicloud's security token service (STS), then the AccessKeyId, AccessKeySecret and STS token are all got from STS.
  119. * Use this: $ossClient = new OssClient($id, $key, $endpoint, false, $token)
  120. * 4. If the endpoint is in IP format, you could use this: $ossClient = new OssClient($id, $key, “1.2.3.4:8900”)
  121. *
  122. * @param string $accessKeyId The AccessKeyId from OSS or STS
  123. * @param string $accessKeySecret The AccessKeySecret from OSS or STS
  124. * @param string $endpoint The domain name of the datacenter,For example: oss-cn-hangzhou.aliyuncs.com
  125. * @param boolean $isCName If this is the CName and binded in the bucket.
  126. * @param string $securityToken from STS.
  127. * @param string $requestProxy
  128. * @throws OssException
  129. */
  130. private function __initClient($accessKeyId, $accessKeySecret, $endpoint, $isCName = false, $securityToken = NULL, $requestProxy = NULL)
  131. {
  132. $accessKeyId = trim($accessKeyId);
  133. $accessKeySecret = trim($accessKeySecret);
  134. $endpoint = trim(trim($endpoint), "/");
  135. if (empty($accessKeyId)) {
  136. throw new OssException("access key id is empty");
  137. }
  138. if (empty($accessKeySecret)) {
  139. throw new OssException("access key secret is empty");
  140. }
  141. $provider = new StaticCredentialsProvider($accessKeyId, $accessKeySecret, $securityToken);
  142. $config = array(
  143. 'endpoint' => $endpoint,
  144. 'cname' => $isCName,
  145. 'request_proxy' => $requestProxy,
  146. 'provider' => $provider
  147. );
  148. $this->__initNewClient($config);
  149. }
  150. /**
  151. * @param array $config
  152. * @throws OssException
  153. */
  154. private function __initNewClient($config = array())
  155. {
  156. $isCName = isset($config['cname']) ? $config['cname'] : false;
  157. $endpoint = isset($config['endpoint']) ? $config['endpoint'] : '';
  158. $requestProxy = isset($config['request_proxy']) ? $config['request_proxy'] : null;
  159. $provider = isset($config['provider']) ? $config['provider'] : '';
  160. if (empty($endpoint)) {
  161. throw new OssException("endpoint is empty");
  162. }
  163. $this->hostname = $this->checkEndpoint($endpoint, $isCName);
  164. $this->requestProxy = $requestProxy;
  165. if (!$provider instanceof CredentialsProvider) {
  166. throw new OssException("provider must be an instance of CredentialsProvider");
  167. }
  168. $this->provider = $provider;
  169. $this->region = isset($config['region']) ? $config['region'] : '';
  170. $this->cloudBoxId = isset($config['cloudBoxId']) ? $config['cloudBoxId'] : '';
  171. // $enableStrictObjName
  172. $this->enableStrictObjName = true;
  173. if (isset($config['strictObjectName'])) {
  174. if ($config['strictObjectName'] === false) {
  175. $this->enableStrictObjName = false;
  176. }
  177. }
  178. // sign version
  179. $signatureVersion = self::OSS_SIGNATURE_VERSION_V1;
  180. if (isset($config['signatureVersion']) && $config['signatureVersion'] === self::OSS_SIGNATURE_VERSION_V4) {
  181. $signatureVersion = self::OSS_SIGNATURE_VERSION_V4;
  182. }
  183. if ($signatureVersion === self::OSS_SIGNATURE_VERSION_V4) {
  184. $this->enableStrictObjName = false;
  185. $this->signer = new SignerV4();
  186. } else {
  187. $this->signer = new SignerV1();
  188. }
  189. //checkObjectEncoding
  190. $this->checkObjectEncoding = false;
  191. if (isset($config['checkObjectEncoding'])) {
  192. if ($config['checkObjectEncoding'] === true) {
  193. $this->checkObjectEncoding = true;
  194. }
  195. }
  196. //filePathCompatible
  197. $this->filePathCompatible = false;
  198. if (version_compare(phpversion(), '7.0.0', '<')) {
  199. if (OssUtil::isWin()) {
  200. $this->filePathCompatible = true;
  201. }
  202. }
  203. if (isset($config['filePathCompatible'])) {
  204. if ($config['filePathCompatible'] === true) {
  205. $this->filePathCompatible = true;
  206. } else if ($config['filePathCompatible'] === false) {
  207. $this->filePathCompatible = false;
  208. }
  209. }
  210. self::checkEnv();
  211. }
  212. /**
  213. * Lists the Bucket [GetService]. Not applicable if the endpoint is CName (because CName must be binded to a specific bucket).
  214. *
  215. * @param array $options
  216. * @return BucketListInfo|null
  217. * @throws OssException|RequestCore_Exception
  218. */
  219. public function listBuckets($options = NULL)
  220. {
  221. if ($this->hostType === self::OSS_HOST_TYPE_CNAME) {
  222. throw new OssException("operation is not permitted with CName host");
  223. }
  224. $this->precheckOptions($options);
  225. $options[self::OSS_BUCKET] = '';
  226. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  227. $response = $this->auth($options);
  228. $result = new ListBucketsResult($response);
  229. return $result->getData();
  230. }
  231. /**
  232. * Creates bucket,The ACL of the bucket created by default is OssClient::OSS_ACL_TYPE_PRIVATE
  233. *
  234. * @param string $bucket
  235. * @param string $acl
  236. * @param array $options
  237. * @return null
  238. * @throws OssException|RequestCore_Exception
  239. */
  240. public function createBucket($bucket, $acl = self::OSS_ACL_TYPE_PRIVATE, $options = NULL)
  241. {
  242. $this->precheckCommon($bucket, NULL, $options, false);
  243. $options[self::OSS_BUCKET] = $bucket;
  244. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  245. $options[self::OSS_HEADERS][self::OSS_ACL] = $acl;
  246. if (isset($options[self::OSS_STORAGE])) {
  247. $this->precheckStorage($options[self::OSS_STORAGE]);
  248. $options[self::OSS_CONTENT] = OssUtil::createBucketXmlBody($options[self::OSS_STORAGE]);
  249. unset($options[self::OSS_STORAGE]);
  250. }
  251. $response = $this->auth($options);
  252. $result = new PutSetDeleteResult($response);
  253. return $result->getData();
  254. }
  255. /**
  256. * Deletes bucket
  257. * The deletion will not succeed if the bucket is not empty (either has objects or parts)
  258. * To delete a bucket, all its objects and parts must be deleted first.
  259. *
  260. * @param string $bucket
  261. * @param array $options
  262. * @return null
  263. * @throws OssException|RequestCore_Exception
  264. */
  265. public function deleteBucket($bucket, $options = NULL)
  266. {
  267. $this->precheckCommon($bucket, NULL, $options, false);
  268. $options[self::OSS_BUCKET] = $bucket;
  269. $options[self::OSS_METHOD] = self::OSS_HTTP_DELETE;
  270. $response = $this->auth($options);
  271. $result = new PutSetDeleteResult($response);
  272. return $result->getData();
  273. }
  274. /**
  275. * Checks if a bucket exists
  276. *
  277. * @param string $bucket
  278. * @return bool|null
  279. * @throws OssException|RequestCore_Exception
  280. */
  281. public function doesBucketExist($bucket)
  282. {
  283. $this->precheckCommon($bucket, NULL, $options, false);
  284. $options[self::OSS_BUCKET] = $bucket;
  285. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  286. $options[self::OSS_SUB_RESOURCE] = 'acl';
  287. $response = $this->auth($options);
  288. $result = new ExistResult($response);
  289. return $result->getData();
  290. }
  291. /**
  292. * Get the data center location information for the bucket
  293. *
  294. * @param string $bucket
  295. * @param array $options
  296. * @return string|null
  297. * @throws OssException|RequestCore_Exception
  298. */
  299. public function getBucketLocation($bucket, $options = NULL)
  300. {
  301. $this->precheckCommon($bucket, NULL, $options, false);
  302. $options[self::OSS_BUCKET] = $bucket;
  303. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  304. $options[self::OSS_SUB_RESOURCE] = 'location';
  305. $response = $this->auth($options);
  306. $result = new GetLocationResult($response);
  307. return $result->getData();
  308. }
  309. /**
  310. * Get the Meta information for the Bucket
  311. *
  312. * @param string $bucket
  313. * @param array $options Refer to the SDK documentation
  314. * @return array|null
  315. * @throws OssException|RequestCore_Exception
  316. */
  317. public function getBucketMeta($bucket, $options = NULL)
  318. {
  319. $this->precheckCommon($bucket, NULL, $options, false);
  320. $options[self::OSS_BUCKET] = $bucket;
  321. $options[self::OSS_METHOD] = self::OSS_HTTP_HEAD;
  322. $response = $this->auth($options);
  323. $result = new HeaderResult($response);
  324. return $result->getData();
  325. }
  326. /**
  327. * Gets the bucket ACL
  328. *
  329. * @param string $bucket
  330. * @param array $options
  331. * @return string|null
  332. * @throws OssException|RequestCore_Exception
  333. */
  334. public function getBucketAcl($bucket, $options = NULL)
  335. {
  336. $this->precheckCommon($bucket, NULL, $options, false);
  337. $options[self::OSS_BUCKET] = $bucket;
  338. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  339. $options[self::OSS_SUB_RESOURCE] = 'acl';
  340. $response = $this->auth($options);
  341. $result = new AclResult($response);
  342. return $result->getData();
  343. }
  344. /**
  345. * Sets the bucket ACL
  346. *
  347. * @param string $bucket bucket name
  348. * @param string $acl access permissions, valid values are ['private', 'public-read', 'public-read-write']
  349. * @param array $options by default is empty
  350. * @return null
  351. * @throws OssException|RequestCore_Exception
  352. */
  353. public function putBucketAcl($bucket, $acl, $options = NULL)
  354. {
  355. $this->precheckCommon($bucket, NULL, $options, false);
  356. $options[self::OSS_BUCKET] = $bucket;
  357. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  358. $options[self::OSS_HEADERS][self::OSS_ACL] = $acl;
  359. $options[self::OSS_SUB_RESOURCE] = 'acl';
  360. $response = $this->auth($options);
  361. $result = new PutSetDeleteResult($response);
  362. return $result->getData();
  363. }
  364. /**
  365. * Gets object ACL
  366. *
  367. * @param string $bucket
  368. * @param string $object
  369. * @param array $options
  370. * @return string|null
  371. * @throws OssException|RequestCore_Exception
  372. */
  373. public function getObjectAcl($bucket, $object, $options = NULL)
  374. {
  375. $this->precheckCommon($bucket, $object, $options, true);
  376. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  377. $options[self::OSS_BUCKET] = $bucket;
  378. $options[self::OSS_OBJECT] = $object;
  379. $options[self::OSS_SUB_RESOURCE] = 'acl';
  380. $response = $this->auth($options);
  381. $result = new AclResult($response);
  382. return $result->getData();
  383. }
  384. /**
  385. * Sets the object ACL
  386. *
  387. * @param string $bucket bucket name
  388. * @param string $object object name
  389. * @param string $acl access permissions, valid values are ['default', 'private', 'public-read', 'public-read-write']
  390. * @param array $options
  391. * @return null
  392. * @throws OssException|RequestCore_Exception
  393. */
  394. public function putObjectAcl($bucket, $object, $acl, $options = NULL)
  395. {
  396. $this->precheckCommon($bucket, $object, $options, true);
  397. $options[self::OSS_BUCKET] = $bucket;
  398. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  399. $options[self::OSS_OBJECT] = $object;
  400. $options[self::OSS_HEADERS][self::OSS_OBJECT_ACL] = $acl;
  401. $options[self::OSS_SUB_RESOURCE] = 'acl';
  402. $response = $this->auth($options);
  403. $result = new PutSetDeleteResult($response);
  404. return $result->getData();
  405. }
  406. /**
  407. * Gets the bucket logging config
  408. *
  409. * @param string $bucket bucket name
  410. * @param array $options by default is empty
  411. * @return LoggingConfig|null
  412. * @throws OssException|RequestCore_Exception
  413. */
  414. public function getBucketLogging($bucket, $options = NULL)
  415. {
  416. $this->precheckCommon($bucket, NULL, $options, false);
  417. $options[self::OSS_BUCKET] = $bucket;
  418. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  419. $options[self::OSS_SUB_RESOURCE] = 'logging';
  420. $response = $this->auth($options);
  421. $result = new GetLoggingResult($response);
  422. return $result->getData();
  423. }
  424. /**
  425. * Sets the bycket logging config. Only owner can call this API.
  426. *
  427. * @param string $bucket bucket name
  428. * @param string $targetBucket The logging file's bucket
  429. * @param string $targetPrefix The logging file's prefix
  430. * @param array $options By default is empty.
  431. * @return null
  432. * @throws OssException|RequestCore_Exception
  433. */
  434. public function putBucketLogging($bucket, $targetBucket, $targetPrefix, $options = NULL)
  435. {
  436. $this->precheckCommon($bucket, NULL, $options, false);
  437. $this->precheckBucket($targetBucket, 'targetbucket is not allowed empty');
  438. $options[self::OSS_BUCKET] = $bucket;
  439. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  440. $options[self::OSS_SUB_RESOURCE] = 'logging';
  441. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  442. $loggingConfig = new LoggingConfig($targetBucket, $targetPrefix);
  443. $options[self::OSS_CONTENT] = $loggingConfig->serializeToXml();
  444. $response = $this->auth($options);
  445. $result = new PutSetDeleteResult($response);
  446. return $result->getData();
  447. }
  448. /**
  449. * Deletes the bucket logging config
  450. *
  451. * @param string $bucket bucket name
  452. * @param array $options
  453. * @return null
  454. * @throws OssException|RequestCore_Exception
  455. */
  456. public function deleteBucketLogging($bucket, $options = NULL)
  457. {
  458. $this->precheckCommon($bucket, NULL, $options, false);
  459. $options[self::OSS_BUCKET] = $bucket;
  460. $options[self::OSS_METHOD] = self::OSS_HTTP_DELETE;
  461. $options[self::OSS_SUB_RESOURCE] = 'logging';
  462. $response = $this->auth($options);
  463. $result = new PutSetDeleteResult($response);
  464. return $result->getData();
  465. }
  466. /**
  467. * Sets the website config in bucket---that is could make the bucket as a static website once the CName is binded.
  468. *
  469. * @param string $bucket bucket name
  470. * @param WebsiteConfig $websiteConfig
  471. * @param array $options
  472. * @return null
  473. * @throws OssException|RequestCore_Exception
  474. */
  475. public function putBucketWebsite($bucket, $websiteConfig, $options = NULL)
  476. {
  477. $this->precheckCommon($bucket, NULL, $options, false);
  478. $options[self::OSS_BUCKET] = $bucket;
  479. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  480. $options[self::OSS_SUB_RESOURCE] = 'website';
  481. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  482. $options[self::OSS_CONTENT] = $websiteConfig->serializeToXml();
  483. $response = $this->auth($options);
  484. $result = new PutSetDeleteResult($response);
  485. return $result->getData();
  486. }
  487. /**
  488. * Gets the website config in the bucket
  489. *
  490. * @param string $bucket bucket name
  491. * @param array $options
  492. * @return WebsiteConfig|null
  493. * @throws OssException|RequestCore_Exception
  494. */
  495. public function getBucketWebsite($bucket, $options = NULL)
  496. {
  497. $this->precheckCommon($bucket, NULL, $options, false);
  498. $options[self::OSS_BUCKET] = $bucket;
  499. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  500. $options[self::OSS_SUB_RESOURCE] = 'website';
  501. $response = $this->auth($options);
  502. $result = new GetWebsiteResult($response);
  503. return $result->getData();
  504. }
  505. /**
  506. * Deletes the website config in the bucket
  507. *
  508. * @param string $bucket bucket name
  509. * @param array $options
  510. * @return null
  511. * @throws OssException|RequestCore_Exception
  512. */
  513. public function deleteBucketWebsite($bucket, $options = NULL)
  514. {
  515. $this->precheckCommon($bucket, NULL, $options, false);
  516. $options[self::OSS_BUCKET] = $bucket;
  517. $options[self::OSS_METHOD] = self::OSS_HTTP_DELETE;
  518. $options[self::OSS_SUB_RESOURCE] = 'website';
  519. $response = $this->auth($options);
  520. $result = new PutSetDeleteResult($response);
  521. return $result->getData();
  522. }
  523. /**
  524. * Sets the cross-origin-resource-sharing (CORS) rule. It would overwrite the originl one.
  525. *
  526. * @param string $bucket bucket name
  527. * @param CorsConfig $corsConfig CORS config. Check out the details from OSS API document
  528. * @param array $options array
  529. * @return null
  530. * @throws OssException|RequestCore_Exception
  531. */
  532. public function putBucketCors($bucket, $corsConfig, $options = NULL)
  533. {
  534. $this->precheckCommon($bucket, NULL, $options, false);
  535. $options[self::OSS_BUCKET] = $bucket;
  536. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  537. $options[self::OSS_SUB_RESOURCE] = 'cors';
  538. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  539. $options[self::OSS_CONTENT] = $corsConfig->serializeToXml();
  540. $response = $this->auth($options);
  541. $result = new PutSetDeleteResult($response);
  542. return $result->getData();
  543. }
  544. /**
  545. * Gets the bucket CORS config
  546. *
  547. * @param string $bucket bucket name
  548. * @param array $options
  549. * @return CorsConfig|null
  550. * @throws OssException|RequestCore_Exception
  551. */
  552. public function getBucketCors($bucket, $options = NULL)
  553. {
  554. $this->precheckCommon($bucket, NULL, $options, false);
  555. $options[self::OSS_BUCKET] = $bucket;
  556. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  557. $options[self::OSS_SUB_RESOURCE] = 'cors';
  558. $response = $this->auth($options);
  559. $result = new GetCorsResult($response);
  560. return $result->getData();
  561. }
  562. /**
  563. * Deletes the bucket's CORS config and disable the CORS on the bucket.
  564. *
  565. * @param string $bucket bucket name
  566. * @param array $options
  567. * @return null
  568. * @throws OssException|RequestCore_Exception
  569. */
  570. public function deleteBucketCors($bucket, $options = NULL)
  571. {
  572. $this->precheckCommon($bucket, NULL, $options, false);
  573. $options[self::OSS_BUCKET] = $bucket;
  574. $options[self::OSS_METHOD] = self::OSS_HTTP_DELETE;
  575. $options[self::OSS_SUB_RESOURCE] = 'cors';
  576. $response = $this->auth($options);
  577. $result = new PutSetDeleteResult($response);
  578. return $result->getData();
  579. }
  580. /**
  581. * Bind a CName for the bucket
  582. *
  583. * @param string $bucket bucket name
  584. * @param string $cname
  585. * @param array $options
  586. * @return null
  587. * @throws OssException|RequestCore_Exception
  588. */
  589. public function addBucketCname($bucket, $cname, $options = NULL)
  590. {
  591. $this->precheckCommon($bucket, NULL, $options, false);
  592. $options[self::OSS_BUCKET] = $bucket;
  593. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  594. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  595. $cnameConfig = new CnameConfig();
  596. $cnameConfig->addCname($cname);
  597. $options[self::OSS_CONTENT] = $cnameConfig->serializeToXml();
  598. $options[self::OSS_COMP] = 'add';
  599. $options[self::OSS_CNAME] = '';
  600. $response = $this->auth($options);
  601. $result = new PutSetDeleteResult($response);
  602. return $result->getData();
  603. }
  604. /**
  605. * Gets the binded CName list of the bucket
  606. *
  607. * @param string $bucket bucket name
  608. * @param array $options
  609. * @return CnameConfig|null
  610. * @throws OssException|RequestCore_Exception
  611. */
  612. public function getBucketCname($bucket, $options = NULL)
  613. {
  614. $this->precheckCommon($bucket, NULL, $options, false);
  615. $options[self::OSS_BUCKET] = $bucket;
  616. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  617. $options[self::OSS_CNAME] = '';
  618. $response = $this->auth($options);
  619. $result = new GetCnameResult($response);
  620. return $result->getData();
  621. }
  622. /**
  623. * Remove a CName binding from the bucket
  624. *
  625. * @param string $bucket bucket name
  626. * @param CnameConfig $cname
  627. * @param array $options
  628. * @return null
  629. * @throws OssException|RequestCore_Exception
  630. */
  631. public function deleteBucketCname($bucket, $cname, $options = NULL)
  632. {
  633. $this->precheckCommon($bucket, NULL, $options, false);
  634. $options[self::OSS_BUCKET] = $bucket;
  635. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  636. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  637. $cnameConfig = new CnameConfig();
  638. $cnameConfig->addCname($cname);
  639. $options[self::OSS_CONTENT] = $cnameConfig->serializeToXml();
  640. $options[self::OSS_COMP] = 'delete';
  641. $options[self::OSS_CNAME] = '';
  642. $response = $this->auth($options);
  643. $result = new PutSetDeleteResult($response);
  644. return $result->getData();
  645. }
  646. /**
  647. * create a cname token for a bucket
  648. *
  649. * @param string $bucket bucket name
  650. * @param array $options
  651. * @return CnameTokenInfo|null
  652. * @throws OssException|RequestCore_Exception
  653. */
  654. public function createBucketCnameToken($bucket, $cname, $options = NULL)
  655. {
  656. $this->precheckCommon($bucket, NULL, $options, false);
  657. $options[self::OSS_BUCKET] = $bucket;
  658. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  659. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  660. $cnameConfig = new CnameConfig();
  661. $cnameConfig->addCname($cname);
  662. $options[self::OSS_CONTENT] = $cnameConfig->serializeToXml();
  663. $options[self::OSS_COMP] = 'token';
  664. $options[self::OSS_CNAME] = '';
  665. $response = $this->auth($options);
  666. $result = new CreateBucketCnameTokenResult($response);
  667. return $result->getData();
  668. }
  669. /**
  670. * get a cname token for a bucket
  671. *
  672. * @param string $bucket bucket name
  673. * @param array $options
  674. * @return CnameTokenInfo|null
  675. * @throws OssException|RequestCore_Exception
  676. */
  677. public function getBucketCnameToken($bucket, $cname, $options = NULL)
  678. {
  679. $this->precheckCommon($bucket, NULL, $options, false);
  680. $options[self::OSS_BUCKET] = $bucket;
  681. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  682. $options[self::OSS_COMP] = 'token';
  683. $options[self::OSS_CNAME] = $cname;
  684. $response = $this->auth($options);
  685. $result = new GetBucketCnameTokenResult($response);
  686. return $result->getData();
  687. }
  688. /**
  689. * Creates a Live Channel under a bucket
  690. *
  691. * @param string $bucket bucket name
  692. * @param string channelName $channelName
  693. * @param LiveChannelConfig $channelConfig
  694. * @param array $options
  695. * @return LiveChannelInfo|null
  696. * @throws OssException|RequestCore_Exception
  697. */
  698. public function putBucketLiveChannel($bucket, $channelName, $channelConfig, $options = NULL)
  699. {
  700. $this->precheckCommon($bucket, NULL, $options, false);
  701. $options[self::OSS_BUCKET] = $bucket;
  702. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  703. $options[self::OSS_OBJECT] = $channelName;
  704. $options[self::OSS_SUB_RESOURCE] = 'live';
  705. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  706. $options[self::OSS_CONTENT] = $channelConfig->serializeToXml();
  707. $response = $this->auth($options);
  708. $result = new PutLiveChannelResult($response);
  709. $info = $result->getData();
  710. $info->setName($channelName);
  711. $info->setDescription($channelConfig->getDescription());
  712. return $info;
  713. }
  714. /**
  715. * Sets the LiveChannel status
  716. *
  717. * @param string $bucket bucket name
  718. * @param string channelName $channelName
  719. * @param string channelStatus $channelStatus enabled or disabled
  720. * @param array $options
  721. * @return null
  722. * @throws OssException|RequestCore_Exception
  723. */
  724. public function putLiveChannelStatus($bucket, $channelName, $channelStatus, $options = NULL)
  725. {
  726. $this->precheckCommon($bucket, NULL, $options, false);
  727. $options[self::OSS_BUCKET] = $bucket;
  728. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  729. $options[self::OSS_OBJECT] = $channelName;
  730. $options[self::OSS_SUB_RESOURCE] = 'live';
  731. $options[self::OSS_LIVE_CHANNEL_STATUS] = $channelStatus;
  732. $response = $this->auth($options);
  733. $result = new PutSetDeleteResult($response);
  734. return $result->getData();
  735. }
  736. /**
  737. * Gets the LiveChannel information by the channel name
  738. *
  739. * @param string $bucket bucket name
  740. * @param string channelName $channelName
  741. * @param array $options
  742. * @return GetLiveChannelInfo|null
  743. * @throws OssException|RequestCore_Exception
  744. */
  745. public function getLiveChannelInfo($bucket, $channelName, $options = NULL)
  746. {
  747. $this->precheckCommon($bucket, NULL, $options, false);
  748. $options[self::OSS_BUCKET] = $bucket;
  749. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  750. $options[self::OSS_OBJECT] = $channelName;
  751. $options[self::OSS_SUB_RESOURCE] = 'live';
  752. $response = $this->auth($options);
  753. $result = new GetLiveChannelInfoResult($response);
  754. return $result->getData();
  755. }
  756. /**
  757. * Gets the status of LiveChannel
  758. *
  759. * @param string $bucket bucket name
  760. * @param string channelName $channelName
  761. * @param array $options
  762. * @return GetLiveChannelStatus|null
  763. * @throws OssException|RequestCore_Exception
  764. */
  765. public function getLiveChannelStatus($bucket, $channelName, $options = NULL)
  766. {
  767. $this->precheckCommon($bucket, NULL, $options, false);
  768. $options[self::OSS_BUCKET] = $bucket;
  769. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  770. $options[self::OSS_OBJECT] = $channelName;
  771. $options[self::OSS_SUB_RESOURCE] = 'live';
  772. $options[self::OSS_COMP] = 'stat';
  773. $response = $this->auth($options);
  774. $result = new GetLiveChannelStatusResult($response);
  775. return $result->getData();
  776. }
  777. /**
  778. * Gets the LiveChannel pushing streaming record
  779. *
  780. * @param string $bucket bucket name
  781. * @param string channelName $channelName
  782. * @param array $options
  783. * @return GetLiveChannelHistory|null
  784. * @throws OssException|RequestCore_Exception
  785. */
  786. public function getLiveChannelHistory($bucket, $channelName, $options = NULL)
  787. {
  788. $this->precheckCommon($bucket, NULL, $options, false);
  789. $options[self::OSS_BUCKET] = $bucket;
  790. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  791. $options[self::OSS_OBJECT] = $channelName;
  792. $options[self::OSS_SUB_RESOURCE] = 'live';
  793. $options[self::OSS_COMP] = 'history';
  794. $response = $this->auth($options);
  795. $result = new GetLiveChannelHistoryResult($response);
  796. return $result->getData();
  797. }
  798. /**
  799. *Gets the live channel list under a bucket.
  800. *
  801. * @param string $bucket bucket name
  802. * @param array $options
  803. * @return LiveChannelListInfo|null
  804. * @throws OssException|RequestCore_Exception
  805. */
  806. public function listBucketLiveChannels($bucket, $options = NULL)
  807. {
  808. $this->precheckCommon($bucket, NULL, $options, false);
  809. $options[self::OSS_BUCKET] = $bucket;
  810. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  811. $options[self::OSS_SUB_RESOURCE] = 'live';
  812. $options[self::OSS_QUERY_STRING] = array(
  813. 'prefix' => isset($options['prefix']) ? $options['prefix'] : '',
  814. 'marker' => isset($options['marker']) ? $options['marker'] : '',
  815. 'max-keys' => isset($options['max-keys']) ? $options['max-keys'] : '',
  816. );
  817. $response = $this->auth($options);
  818. $result = new ListLiveChannelResult($response);
  819. $list = $result->getData();
  820. $list->setBucketName($bucket);
  821. return $list;
  822. }
  823. /**
  824. * Creates a play list file for the LiveChannel
  825. *
  826. * @param string $bucket bucket name
  827. * @param string channelName $channelName
  828. * @param string $playlistName The playlist name, must end with ".m3u8".
  829. * @param array $setTime startTime and EndTime in unix time. No more than 1 day.
  830. * @return null
  831. * @throws OssException|RequestCore_Exception
  832. */
  833. public function postVodPlaylist($bucket, $channelName, $playlistName, $setTime)
  834. {
  835. $this->precheckCommon($bucket, NULL, $options, false);
  836. $options[self::OSS_BUCKET] = $bucket;
  837. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  838. $options[self::OSS_OBJECT] = $channelName . '/' . $playlistName;
  839. $options[self::OSS_SUB_RESOURCE] = 'vod';
  840. $options[self::OSS_LIVE_CHANNEL_END_TIME] = $setTime['EndTime'];
  841. $options[self::OSS_LIVE_CHANNEL_START_TIME] = $setTime['StartTime'];
  842. $response = $this->auth($options);
  843. $result = new PutSetDeleteResult($response);
  844. return $result->getData();
  845. }
  846. /**
  847. * Deletes the Bucket LiveChannel
  848. *
  849. * @param string $bucket bucket name
  850. * @param string channelName $channelName
  851. * @param array $options
  852. * @return null
  853. * @throws OssException|RequestCore_Exception
  854. */
  855. public function deleteBucketLiveChannel($bucket, $channelName, $options = NULL)
  856. {
  857. $this->precheckCommon($bucket, NULL, $options, false);
  858. $options[self::OSS_BUCKET] = $bucket;
  859. $options[self::OSS_METHOD] = self::OSS_HTTP_DELETE;
  860. $options[self::OSS_OBJECT] = $channelName;
  861. $options[self::OSS_SUB_RESOURCE] = 'live';
  862. $response = $this->auth($options);
  863. $result = new PutSetDeleteResult($response);
  864. return $result->getData();
  865. }
  866. /**
  867. * Generates the signed pushing streaming url
  868. *
  869. * @param string $bucket bucket name
  870. * @param string channelName $channelName
  871. * @param int timeout timeout value in seconds
  872. * @param array $options
  873. * @return string The signed pushing streaming url
  874. * @throws OssException
  875. */
  876. public function signRtmpUrl($bucket, $channelName, $timeout = 60, $options = NULL)
  877. {
  878. $this->precheckCommon($bucket, $channelName, $options, false);
  879. $expires = time() + $timeout;
  880. $proto = 'rtmp://';
  881. $hostname = $this->generateHostname($bucket);
  882. $cano_params = '';
  883. $query_items = array();
  884. $params = isset($options['params']) ? $options['params'] : array();
  885. uksort($params, 'strnatcasecmp');
  886. foreach ($params as $key => $value) {
  887. $cano_params = $cano_params . $key . ':' . $value . "\n";
  888. $query_items[] = rawurlencode($key) . '=' . rawurlencode($value);
  889. }
  890. $resource = '/' . $bucket . '/' . $channelName;
  891. $string_to_sign = $expires . "\n" . $cano_params . $resource;
  892. $cred = $this->provider->getCredentials();
  893. $this->checkCredentials($cred);
  894. $signature = base64_encode(hash_hmac('sha1', $string_to_sign, $cred->getAccessKeySecret(), true));
  895. $query_items[] = 'OSSAccessKeyId=' . rawurlencode($cred->getAccessKeyId());
  896. $query_items[] = 'Expires=' . rawurlencode($expires);
  897. $query_items[] = 'Signature=' . rawurlencode($signature);
  898. return $proto . $hostname . '/live/' . $channelName . '?' . implode('&', $query_items);
  899. }
  900. /**
  901. * Generates the signed pushing streaming url
  902. *
  903. * @param string $bucket bucket name
  904. * @param string $channelName channel name
  905. * @param int $expiration expiration time of the Url, unix epoch, since 1970.1.1 00.00.00 UTC
  906. * @param array $options
  907. * @return string The signed pushing streaming url
  908. * @throws OssException
  909. */
  910. public function generatePresignedRtmpUrl($bucket, $channelName, $expiration, $options = NULL)
  911. {
  912. $this->precheckCommon($bucket, $channelName, $options, false);
  913. $proto = 'rtmp://';
  914. $hostname = $this->generateHostname($bucket);
  915. $cano_params = '';
  916. $query_items = array();
  917. $params = isset($options['params']) ? $options['params'] : array();
  918. uksort($params, 'strnatcasecmp');
  919. foreach ($params as $key => $value) {
  920. $cano_params = $cano_params . $key . ':' . $value . "\n";
  921. $query_items[] = rawurlencode($key) . '=' . rawurlencode($value);
  922. }
  923. $resource = '/' . $bucket . '/' . $channelName;
  924. $string_to_sign = $expiration . "\n" . $cano_params . $resource;
  925. $cred = $this->provider->getCredentials();
  926. $this->checkCredentials($cred);
  927. $signature = base64_encode(hash_hmac('sha1', $string_to_sign, $cred->getAccessKeySecret(), true));
  928. $query_items[] = 'OSSAccessKeyId=' . rawurlencode($cred->getAccessKeyId());
  929. $query_items[] = 'Expires=' . rawurlencode($expiration);
  930. $query_items[] = 'Signature=' . rawurlencode($signature);
  931. return $proto . $hostname . '/live/' . $channelName . '?' . implode('&', $query_items);
  932. }
  933. /**
  934. * Precheck the CORS request. Before sending a CORS request, a preflight request (OPTIONS) is sent with the specific origin.
  935. * HTTP METHOD and headers information are sent to OSS as well for evaluating if the CORS request is allowed.
  936. *
  937. * Note: OSS could enable the CORS on the bucket by calling putBucketCors. Once CORS is enabled, the OSS could evaluate accordingto the preflight request.
  938. *
  939. * @param string $bucket bucket name
  940. * @param string $object object name
  941. * @param string $origin the origin of the request
  942. * @param string $request_method The actual HTTP method which will be used in CORS request
  943. * @param string $request_headers The actual HTTP headers which will be used in CORS request
  944. * @param array $options
  945. * @return array|null
  946. * @throws OssException|RequestCore_Exception
  947. */
  948. public function optionsObject($bucket, $object, $origin, $request_method, $request_headers, $options = NULL)
  949. {
  950. $this->precheckCommon($bucket, NULL, $options, false);
  951. $options[self::OSS_BUCKET] = $bucket;
  952. $options[self::OSS_METHOD] = self::OSS_HTTP_OPTIONS;
  953. $options[self::OSS_OBJECT] = $object;
  954. $options[self::OSS_HEADERS][self::OSS_OPTIONS_ORIGIN] = $origin;
  955. $options[self::OSS_HEADERS][self::OSS_OPTIONS_REQUEST_HEADERS] = $request_headers;
  956. $options[self::OSS_HEADERS][self::OSS_OPTIONS_REQUEST_METHOD] = $request_method;
  957. $response = $this->auth($options);
  958. $result = new HeaderResult($response);
  959. return $result->getData();
  960. }
  961. /**
  962. * Sets the bucket's lifecycle config
  963. *
  964. * @param string $bucket bucket name
  965. * @param LifecycleConfig $lifecycleConfig LifecycleConfig instance
  966. * @param array $options
  967. * @return array|null
  968. * @throws OssException|RequestCore_Exception
  969. */
  970. public function putBucketLifecycle($bucket, $lifecycleConfig, $options = NULL)
  971. {
  972. $this->precheckCommon($bucket, NULL, $options, false);
  973. $options[self::OSS_BUCKET] = $bucket;
  974. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  975. $options[self::OSS_SUB_RESOURCE] = 'lifecycle';
  976. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  977. $options[self::OSS_CONTENT] = $lifecycleConfig->serializeToXml();
  978. $response = $this->auth($options);
  979. $result = new PutSetDeleteResult($response);
  980. return $result->getData();
  981. }
  982. /**
  983. * Gets bucket's lifecycle config
  984. *
  985. * @param string $bucket bucket name
  986. * @param array $options
  987. * @return LifecycleConfig|null
  988. * @throws OssException|RequestCore_Exception
  989. */
  990. public function getBucketLifecycle($bucket, $options = NULL)
  991. {
  992. $this->precheckCommon($bucket, NULL, $options, false);
  993. $options[self::OSS_BUCKET] = $bucket;
  994. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  995. $options[self::OSS_SUB_RESOURCE] = 'lifecycle';
  996. $response = $this->auth($options);
  997. $result = new GetLifecycleResult($response);
  998. return $result->getData();
  999. }
  1000. /**
  1001. * Deletes the bucket's lifecycle config
  1002. *
  1003. * @param string $bucket bucket name
  1004. * @param array $options
  1005. * @return array|null
  1006. * @throws OssException|RequestCore_Exception
  1007. */
  1008. public function deleteBucketLifecycle($bucket, $options = NULL)
  1009. {
  1010. $this->precheckCommon($bucket, NULL, $options, false);
  1011. $options[self::OSS_BUCKET] = $bucket;
  1012. $options[self::OSS_METHOD] = self::OSS_HTTP_DELETE;
  1013. $options[self::OSS_SUB_RESOURCE] = 'lifecycle';
  1014. $response = $this->auth($options);
  1015. $result = new PutSetDeleteResult($response);
  1016. return $result->getData();
  1017. }
  1018. /**
  1019. * Sets a bucket's referer, which has a whitelist of referrer and specifies if empty referer is allowed.
  1020. * Checks out API document for more details about "Bucket Referer"
  1021. *
  1022. * @param string $bucket bucket name
  1023. * @param RefererConfig $refererConfig
  1024. * @param array $options
  1025. * @return array|null
  1026. * @throws OssException|RequestCore_Exception
  1027. */
  1028. public function putBucketReferer($bucket, $refererConfig, $options = NULL)
  1029. {
  1030. $this->precheckCommon($bucket, NULL, $options, false);
  1031. $options[self::OSS_BUCKET] = $bucket;
  1032. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  1033. $options[self::OSS_SUB_RESOURCE] = 'referer';
  1034. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  1035. $options[self::OSS_CONTENT] = $refererConfig->serializeToXml();
  1036. $response = $this->auth($options);
  1037. $result = new PutSetDeleteResult($response);
  1038. return $result->getData();
  1039. }
  1040. /**
  1041. * Gets the bucket's Referer
  1042. * Checks out API document for more details about "Bucket Referer"
  1043. *
  1044. * @param string $bucket bucket name
  1045. * @param array $options
  1046. * @return RefererConfig|null
  1047. * @throws OssException|RequestCore_Exception
  1048. */
  1049. public function getBucketReferer($bucket, $options = NULL)
  1050. {
  1051. $this->precheckCommon($bucket, NULL, $options, false);
  1052. $options[self::OSS_BUCKET] = $bucket;
  1053. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  1054. $options[self::OSS_SUB_RESOURCE] = 'referer';
  1055. $response = $this->auth($options);
  1056. $result = new GetRefererResult($response);
  1057. return $result->getData();
  1058. }
  1059. /**
  1060. * Set the size of the bucket,the unit is GB
  1061. * When the capacity of the bucket is bigger than the set, it's forbidden to continue writing
  1062. *
  1063. * @param string $bucket bucket name
  1064. * @param int $storageCapacity
  1065. * @param array $options
  1066. * @return array|null
  1067. * @throws OssException|RequestCore_Exception
  1068. */
  1069. public function putBucketStorageCapacity($bucket, $storageCapacity, $options = NULL)
  1070. {
  1071. $this->precheckCommon($bucket, NULL, $options, false);
  1072. $options[self::OSS_BUCKET] = $bucket;
  1073. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  1074. $options[self::OSS_SUB_RESOURCE] = 'qos';
  1075. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  1076. $storageCapacityConfig = new StorageCapacityConfig($storageCapacity);
  1077. $options[self::OSS_CONTENT] = $storageCapacityConfig->serializeToXml();
  1078. $response = $this->auth($options);
  1079. $result = new PutSetDeleteResult($response);
  1080. return $result->getData();
  1081. }
  1082. /**
  1083. * Get the capacity of the bucket, the unit is GB
  1084. *
  1085. * @param string $bucket bucket name
  1086. * @param array $options
  1087. * @return int|null
  1088. * @throws OssException|RequestCore_Exception
  1089. */
  1090. public function getBucketStorageCapacity($bucket, $options = NULL)
  1091. {
  1092. $this->precheckCommon($bucket, NULL, $options, false);
  1093. $options[self::OSS_BUCKET] = $bucket;
  1094. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  1095. $options[self::OSS_SUB_RESOURCE] = 'qos';
  1096. $response = $this->auth($options);
  1097. $result = new GetStorageCapacityResult($response);
  1098. return $result->getData();
  1099. }
  1100. /**
  1101. * Get the information of the bucket
  1102. *
  1103. * @param string $bucket bucket name
  1104. * @param array $options
  1105. * @return BucketInfo|null
  1106. * @throws OssException|RequestCore_Exception
  1107. */
  1108. public function getBucketInfo($bucket, $options = NULL)
  1109. {
  1110. $this->precheckCommon($bucket, NULL, $options, false);
  1111. $options[self::OSS_BUCKET] = $bucket;
  1112. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  1113. $options[self::OSS_SUB_RESOURCE] = 'bucketInfo';
  1114. $response = $this->auth($options);
  1115. $result = new GetBucketInfoResult($response);
  1116. return $result->getData();
  1117. }
  1118. /**
  1119. * Get the stat of the bucket
  1120. *
  1121. * @param string $bucket bucket name
  1122. * @param array $options
  1123. * @return BucketStat|null
  1124. * @throws OssException|RequestCore_Exception
  1125. */
  1126. public function getBucketStat($bucket, $options = NULL)
  1127. {
  1128. $this->precheckCommon($bucket, NULL, $options, false);
  1129. $options[self::OSS_BUCKET] = $bucket;
  1130. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  1131. $options[self::OSS_SUB_RESOURCE] = 'stat';
  1132. $response = $this->auth($options);
  1133. $result = new GetBucketStatResult($response);
  1134. return $result->getData();
  1135. }
  1136. /**
  1137. * Sets the bucket's policy
  1138. *
  1139. * @param string $bucket bucket name
  1140. * @param string $policy policy json format content
  1141. * @param array $options
  1142. * @return array|null
  1143. * @throws OssException|RequestCore_Exception
  1144. */
  1145. public function putBucketPolicy($bucket, $policy, $options = NULL)
  1146. {
  1147. $this->precheckCommon($bucket, NULL, $options, false);
  1148. $options[self::OSS_BUCKET] = $bucket;
  1149. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  1150. $options[self::OSS_SUB_RESOURCE] = 'policy';
  1151. $options[self::OSS_CONTENT_TYPE] = 'application/json';
  1152. $options[self::OSS_CONTENT] = $policy;
  1153. $response = $this->auth($options);
  1154. $result = new PutSetDeleteResult($response);
  1155. return $result->getData();
  1156. }
  1157. /**
  1158. * Gets bucket's policy
  1159. *
  1160. * @param string $bucket bucket name
  1161. * @param array $options
  1162. * @return string|null policy json content
  1163. * @throws OssException|RequestCore_Exception
  1164. */
  1165. public function getBucketPolicy($bucket, $options = NULL)
  1166. {
  1167. $this->precheckCommon($bucket, NULL, $options, false);
  1168. $options[self::OSS_BUCKET] = $bucket;
  1169. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  1170. $options[self::OSS_SUB_RESOURCE] = 'policy';
  1171. $response = $this->auth($options);
  1172. $result = new BodyResult($response);
  1173. return $result->getData();
  1174. }
  1175. /**
  1176. * Deletes the bucket's policy
  1177. *
  1178. * @param string $bucket bucket name
  1179. * @param array $options
  1180. * @return array|null
  1181. * @throws OssException|RequestCore_Exception
  1182. */
  1183. public function deleteBucketPolicy($bucket, $options = NULL)
  1184. {
  1185. $this->precheckCommon($bucket, NULL, $options, false);
  1186. $options[self::OSS_BUCKET] = $bucket;
  1187. $options[self::OSS_METHOD] = self::OSS_HTTP_DELETE;
  1188. $options[self::OSS_SUB_RESOURCE] = 'policy';
  1189. $response = $this->auth($options);
  1190. $result = new PutSetDeleteResult($response);
  1191. return $result->getData();
  1192. }
  1193. /**
  1194. * Sets the bucket's encryption
  1195. *
  1196. * @param string $bucket bucket name
  1197. * @param ServerSideEncryptionConfig $sseConfig
  1198. * @param array $options
  1199. * @return array|null
  1200. * @throws OssException|RequestCore_Exception
  1201. */
  1202. public function putBucketEncryption($bucket, $sseConfig, $options = NULL)
  1203. {
  1204. $this->precheckCommon($bucket, NULL, $options, false);
  1205. $options[self::OSS_BUCKET] = $bucket;
  1206. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  1207. $options[self::OSS_SUB_RESOURCE] = 'encryption';
  1208. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  1209. $options[self::OSS_CONTENT] = $sseConfig->serializeToXml();
  1210. $response = $this->auth($options);
  1211. $result = new PutSetDeleteResult($response);
  1212. return $result->getData();
  1213. }
  1214. /**
  1215. * Gets bucket's encryption
  1216. *
  1217. * @param string $bucket bucket name
  1218. * @param array $options
  1219. * @return ServerSideEncryptionConfig|null
  1220. * @throws OssException|RequestCore_Exception
  1221. */
  1222. public function getBucketEncryption($bucket, $options = NULL)
  1223. {
  1224. $this->precheckCommon($bucket, NULL, $options, false);
  1225. $options[self::OSS_BUCKET] = $bucket;
  1226. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  1227. $options[self::OSS_SUB_RESOURCE] = 'encryption';
  1228. $response = $this->auth($options);
  1229. $result = new GetBucketEncryptionResult($response);
  1230. return $result->getData();
  1231. }
  1232. /**
  1233. * Deletes the bucket's encryption
  1234. *
  1235. * @param string $bucket bucket name
  1236. * @param array $options
  1237. * @return array|null
  1238. * @throws OssException|RequestCore_Exception
  1239. */
  1240. public function deleteBucketEncryption($bucket, $options = NULL)
  1241. {
  1242. $this->precheckCommon($bucket, NULL, $options, false);
  1243. $options[self::OSS_BUCKET] = $bucket;
  1244. $options[self::OSS_METHOD] = self::OSS_HTTP_DELETE;
  1245. $options[self::OSS_SUB_RESOURCE] = 'encryption';
  1246. $response = $this->auth($options);
  1247. $result = new PutSetDeleteResult($response);
  1248. return $result->getData();
  1249. }
  1250. /**
  1251. * Set the request playment of the bucket, Can be BucketOwner and Requester
  1252. *
  1253. * @param string $bucket bucket name
  1254. * @param string $payer
  1255. * @param array $options
  1256. * @return array|null
  1257. * @throws OssException|RequestCore_Exception
  1258. */
  1259. public function putBucketRequestPayment($bucket, $payer, $options = NULL)
  1260. {
  1261. $this->precheckCommon($bucket, NULL, $options, false);
  1262. $options[self::OSS_BUCKET] = $bucket;
  1263. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  1264. $options[self::OSS_SUB_RESOURCE] = 'requestPayment';
  1265. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  1266. $config = new RequestPaymentConfig($payer);
  1267. $options[self::OSS_CONTENT] = $config->serializeToXml();
  1268. $response = $this->auth($options);
  1269. $result = new PutSetDeleteResult($response);
  1270. return $result->getData();
  1271. }
  1272. /**
  1273. * Get the request playment of the bucket
  1274. *
  1275. * @param string $bucket bucket name
  1276. * @param array $options
  1277. * @return string|null
  1278. * @throws OssException|RequestCore_Exception
  1279. */
  1280. public function getBucketRequestPayment($bucket, $options = NULL)
  1281. {
  1282. $this->precheckCommon($bucket, NULL, $options, false);
  1283. $options[self::OSS_BUCKET] = $bucket;
  1284. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  1285. $options[self::OSS_SUB_RESOURCE] = 'requestPayment';
  1286. $response = $this->auth($options);
  1287. $result = new GetBucketRequestPaymentResult($response);
  1288. return $result->getData();
  1289. }
  1290. /**
  1291. * Sets the bucket's tags
  1292. *
  1293. * @param string $bucket bucket name
  1294. * @param TaggingConfig $taggingConfig
  1295. * @param array $options
  1296. * @return null
  1297. * @throws OssException|RequestCore_Exception
  1298. */
  1299. public function putBucketTags($bucket, $taggingConfig, $options = NULL)
  1300. {
  1301. $this->precheckCommon($bucket, NULL, $options, false);
  1302. $options[self::OSS_BUCKET] = $bucket;
  1303. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  1304. $options[self::OSS_SUB_RESOURCE] = self::OSS_TAGGING;
  1305. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  1306. $options[self::OSS_CONTENT] = $taggingConfig->serializeToXml();
  1307. $response = $this->auth($options);
  1308. $result = new PutSetDeleteResult($response);
  1309. return $result->getData();
  1310. }
  1311. /**
  1312. * Gets bucket's tags
  1313. *
  1314. * @param string $bucket bucket name
  1315. * @param array $options
  1316. * @return TaggingConfig|null
  1317. * @throws OssException|RequestCore_Exception
  1318. */
  1319. public function getBucketTags($bucket, $options = NULL)
  1320. {
  1321. $this->precheckCommon($bucket, NULL, $options, false);
  1322. $options[self::OSS_BUCKET] = $bucket;
  1323. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  1324. $options[self::OSS_SUB_RESOURCE] = self::OSS_TAGGING;
  1325. $response = $this->auth($options);
  1326. $result = new GetBucketTagsResult($response);
  1327. return $result->getData();
  1328. }
  1329. /**
  1330. * Deletes the bucket's tags
  1331. * If want to delete specified tags for a bucket, please set the $tags
  1332. *
  1333. * @param string $bucket bucket name
  1334. * @param tag[] $tags (optional)
  1335. * @param array $options
  1336. * @return array|null
  1337. * @throws OssException|RequestCore_Exception
  1338. */
  1339. public function deleteBucketTags($bucket, $tags = NULL, $options = NULL)
  1340. {
  1341. $this->precheckCommon($bucket, NULL, $options, false);
  1342. $options[self::OSS_BUCKET] = $bucket;
  1343. $options[self::OSS_METHOD] = self::OSS_HTTP_DELETE;
  1344. if (empty($tags)) {
  1345. $options[self::OSS_SUB_RESOURCE] = self::OSS_TAGGING;
  1346. } else {
  1347. $value = '';
  1348. foreach ($tags as $tag) {
  1349. $value .= $tag->getKey() . ',';
  1350. }
  1351. $value = rtrim($value, ',');
  1352. $options[self::OSS_TAGGING] = $value;
  1353. }
  1354. $response = $this->auth($options);
  1355. $result = new PutSetDeleteResult($response);
  1356. return $result->getData();
  1357. }
  1358. /**
  1359. * Set the versioning of the bucket, Can be BucketOwner and Requester
  1360. *
  1361. * @param string $bucket bucket name
  1362. * @param string $status
  1363. * @param array $options
  1364. * @return array|null
  1365. * @throws OssException|RequestCore_Exception
  1366. */
  1367. public function putBucketVersioning($bucket, $status, $options = NULL)
  1368. {
  1369. $this->precheckCommon($bucket, NULL, $options, false);
  1370. $options[self::OSS_BUCKET] = $bucket;
  1371. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  1372. $options[self::OSS_SUB_RESOURCE] = 'versioning';
  1373. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  1374. $config = new VersioningConfig($status);
  1375. $options[self::OSS_CONTENT] = $config->serializeToXml();
  1376. $response = $this->auth($options);
  1377. $result = new PutSetDeleteResult($response);
  1378. return $result->getData();
  1379. }
  1380. /**
  1381. * Get the versioning of the bucket
  1382. *
  1383. * @param string $bucket bucket name
  1384. * @param array $options
  1385. * @return string|null
  1386. * @throws OssException|RequestCore_Exception
  1387. */
  1388. public function getBucketVersioning($bucket, $options = NULL)
  1389. {
  1390. $this->precheckCommon($bucket, NULL, $options, false);
  1391. $options[self::OSS_BUCKET] = $bucket;
  1392. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  1393. $options[self::OSS_SUB_RESOURCE] = 'versioning';
  1394. $response = $this->auth($options);
  1395. $result = new GetBucketVersioningResult($response);
  1396. return $result->getData();
  1397. }
  1398. /**
  1399. * Initialize a bucket's worm
  1400. *
  1401. * @param string $bucket bucket name
  1402. * @param int $day
  1403. * @param array $options
  1404. * @return string|null returns upload id
  1405. * @throws OssException|RequestCore_Exception
  1406. */
  1407. public function initiateBucketWorm($bucket, $day, $options = NULL)
  1408. {
  1409. $this->precheckCommon($bucket, NULL, $options, false);
  1410. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  1411. $options[self::OSS_BUCKET] = $bucket;
  1412. $options[self::OSS_SUB_RESOURCE] = 'worm';
  1413. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  1414. $config = new InitiateWormConfig($day);
  1415. $options[self::OSS_CONTENT] = $config->serializeToXml();
  1416. $response = $this->auth($options);
  1417. $result = new InitiateBucketWormResult($response);
  1418. return $result->getData();
  1419. }
  1420. /**
  1421. * Aborts the bucket's worm
  1422. *
  1423. * @param string $bucket bucket name
  1424. * @param array $options
  1425. * @return array|null
  1426. * @throws OssException|RequestCore_Exception
  1427. */
  1428. public function abortBucketWorm($bucket, $options = NULL)
  1429. {
  1430. $this->precheckCommon($bucket, NULL, $options, false);
  1431. $options[self::OSS_BUCKET] = $bucket;
  1432. $options[self::OSS_METHOD] = self::OSS_HTTP_DELETE;
  1433. $options[self::OSS_SUB_RESOURCE] = 'worm';
  1434. $response = $this->auth($options);
  1435. $result = new PutSetDeleteResult($response);
  1436. return $result->getData();
  1437. }
  1438. /**
  1439. * Complete a bucket's worm
  1440. *
  1441. * @param string $bucket bucket name
  1442. * @param string $wormId
  1443. * @param array $options
  1444. * @return string|null returns upload id
  1445. * @throws OssException|RequestCore_Exception
  1446. */
  1447. public function completeBucketWorm($bucket, $wormId, $options = NULL)
  1448. {
  1449. $this->precheckCommon($bucket, NULL, $options, false);
  1450. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  1451. $options[self::OSS_BUCKET] = $bucket;
  1452. $options[self::OSS_WORM_ID] = $wormId;
  1453. $options[self::OSS_CONTENT] = '';
  1454. $response = $this->auth($options);
  1455. $result = new PutSetDeleteResult($response);
  1456. return $result->getData();
  1457. }
  1458. /**
  1459. * Extend a bucket's worm
  1460. *
  1461. * @param string $bucket bucket name
  1462. * @param string $wormId
  1463. * @param int $day
  1464. * @param array $options
  1465. * @return string|null returns upload id
  1466. * @throws OssException|RequestCore_Exception
  1467. */
  1468. public function extendBucketWorm($bucket, $wormId, $day, $options = NULL)
  1469. {
  1470. $this->precheckCommon($bucket, NULL, $options, false);
  1471. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  1472. $options[self::OSS_BUCKET] = $bucket;
  1473. $options[self::OSS_WORM_ID] = $wormId;
  1474. $options[self::OSS_SUB_RESOURCE] = 'wormExtend';
  1475. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  1476. $config = new ExtendWormConfig($day);
  1477. $options[self::OSS_CONTENT] = $config->serializeToXml();
  1478. $response = $this->auth($options);
  1479. $result = new PutSetDeleteResult($response);
  1480. return $result->getData();
  1481. }
  1482. /**
  1483. * Get a bucket's worm
  1484. *
  1485. * @param string $bucket bucket name
  1486. * @param array $options
  1487. * @return string|null
  1488. * @throws OssException|RequestCore_Exception
  1489. */
  1490. public function getBucketWorm($bucket, $options = NULL)
  1491. {
  1492. $this->precheckCommon($bucket, NULL, $options, false);
  1493. $options[self::OSS_BUCKET] = $bucket;
  1494. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  1495. $options[self::OSS_SUB_RESOURCE] = 'worm';
  1496. $response = $this->auth($options);
  1497. $result = new GetBucketWormResult($response);
  1498. return $result->getData();
  1499. }
  1500. /**
  1501. * Put Bucket TransferAcceleration
  1502. * @param $bucket
  1503. * @param $enabled boolean
  1504. * @param array $options
  1505. * @return array|null
  1506. * @throws OssException|RequestCore_Exception
  1507. */
  1508. public function putBucketTransferAcceleration($bucket, $enabled, $options = NULL)
  1509. {
  1510. $this->precheckCommon($bucket, NULL, $options, false);
  1511. $options[self::OSS_BUCKET] = $bucket;
  1512. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  1513. $options[self::OSS_SUB_RESOURCE] = 'transferAcceleration';
  1514. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  1515. $config = new TransferAccelerationConfig();
  1516. $config->setEnabled($enabled);
  1517. $options[self::OSS_CONTENT] = $config->serializeToXml();
  1518. $response = $this->auth($options);
  1519. $result = new HeaderResult($response);
  1520. return $result->getData();
  1521. }
  1522. /**
  1523. * Put Bucket TransferAcceleration
  1524. * @param $bucket
  1525. * @param array $options
  1526. * @return boolean|null
  1527. * @throws OssException|RequestCore_Exception
  1528. */
  1529. public function getBucketTransferAcceleration($bucket, $options = NULL)
  1530. {
  1531. $this->precheckCommon($bucket, NULL, $options, false);
  1532. $options[self::OSS_BUCKET] = $bucket;
  1533. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  1534. $options[self::OSS_SUB_RESOURCE] = 'transferAcceleration';
  1535. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  1536. $response = $this->auth($options);
  1537. $result = new GetBucketTransferAccelerationResult($response);
  1538. return $result->getData();
  1539. }
  1540. /**
  1541. * Lists the bucket's object list (in ObjectListInfo)
  1542. *
  1543. * @param string $bucket
  1544. * @param array $options are defined below:
  1545. * $options = array(
  1546. * 'max-keys' => specifies max object count to return. By default is 100 and max value could be 1000.
  1547. * 'prefix' => specifies the key prefix the returned objects must have. Note that the returned keys still contain the prefix.
  1548. * 'delimiter' => The delimiter of object name for grouping object. When it's specified, listObjects will differeniate the object and folder. And it will return subfolder's objects.
  1549. * 'marker' => The key of returned object must be greater than the 'marker'.
  1550. *)
  1551. * Prefix and marker are for filtering and paging. Their length must be less than 256 bytes
  1552. * @return ObjectListInfo|null
  1553. * @throws OssException|RequestCore_Exception
  1554. */
  1555. public function listObjects($bucket, $options = NULL)
  1556. {
  1557. $this->precheckCommon($bucket, NULL, $options, false);
  1558. $options[self::OSS_BUCKET] = $bucket;
  1559. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  1560. $query = isset($options[self::OSS_QUERY_STRING]) ? $options[self::OSS_QUERY_STRING] : array();
  1561. $options[self::OSS_QUERY_STRING] = array_merge(
  1562. $query,
  1563. array(self::OSS_ENCODING_TYPE => self::OSS_ENCODING_TYPE_URL,
  1564. self::OSS_DELIMITER => isset($options[self::OSS_DELIMITER]) ? $options[self::OSS_DELIMITER] : '/',
  1565. self::OSS_PREFIX => isset($options[self::OSS_PREFIX]) ? $options[self::OSS_PREFIX] : '',
  1566. self::OSS_MAX_KEYS => isset($options[self::OSS_MAX_KEYS]) ? $options[self::OSS_MAX_KEYS] : self::OSS_MAX_KEYS_VALUE,
  1567. self::OSS_MARKER => isset($options[self::OSS_MARKER]) ? $options[self::OSS_MARKER] : '')
  1568. );
  1569. $response = $this->auth($options);
  1570. $result = new ListObjectsResult($response);
  1571. return $result->getData();
  1572. }
  1573. /**
  1574. * Lists the bucket's object list v2 (in ObjectListInfoV2)
  1575. *
  1576. * @param string $bucket
  1577. * @param array $options are defined below:
  1578. * $options = array(
  1579. * 'max-keys' => specifies max object count to return. By default is 100 and max value could be 1000.
  1580. * 'prefix' => specifies the key prefix the returned objects must have. Note that the returned keys still contain the prefix.
  1581. * 'delimiter' => The delimiter of object name for grouping object. When it's specified, listObjects will differeniate the object and folder. And it will return subfolder's objects.
  1582. * 'start-after' => The key of returned object must be greater than the 'start-after'.
  1583. * 'continuation-token' => The token from which the list operation must start.
  1584. *)
  1585. * Prefix, start-after and continuation-token are for filtering and paging. Their length must be less than 256 bytes
  1586. * @return ObjectListInfoV2|null
  1587. * @throws OssException|RequestCore_Exception
  1588. */
  1589. public function listObjectsV2($bucket, $options = NULL)
  1590. {
  1591. $this->precheckCommon($bucket, NULL, $options, false);
  1592. $options[self::OSS_BUCKET] = $bucket;
  1593. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  1594. $query = isset($options[self::OSS_QUERY_STRING]) ? $options[self::OSS_QUERY_STRING] : array();
  1595. $temp = array(
  1596. self::OSS_LIST_TYPE => 2,
  1597. self::OSS_ENCODING_TYPE => self::OSS_ENCODING_TYPE_URL,
  1598. self::OSS_DELIMITER => isset($options[self::OSS_DELIMITER]) ? $options[self::OSS_DELIMITER] : '/',
  1599. self::OSS_PREFIX => isset($options[self::OSS_PREFIX]) ? $options[self::OSS_PREFIX] : '',
  1600. self::OSS_MAX_KEYS => isset($options[self::OSS_MAX_KEYS]) ? $options[self::OSS_MAX_KEYS] : self::OSS_MAX_KEYS_VALUE,
  1601. self::OSS_START_AFTER => isset($options[self::OSS_START_AFTER]) ? $options[self::OSS_START_AFTER] : '',
  1602. );
  1603. if (isset($options[self::OSS_CONTINUATION_TOKEN])) {
  1604. $temp[self::OSS_CONTINUATION_TOKEN] = $options[self::OSS_CONTINUATION_TOKEN];
  1605. }
  1606. $options[self::OSS_QUERY_STRING] = array_merge(
  1607. $query, $temp
  1608. );
  1609. $response = $this->auth($options);
  1610. $result = new ListObjectsV2Result($response);
  1611. return $result->getData();
  1612. }
  1613. /**
  1614. * Lists the bucket's object with version information (in ObjectListInfo)
  1615. *
  1616. * @param string $bucket
  1617. * @param array $options are defined below:
  1618. * $options = array(
  1619. * 'max-keys' => specifies max object count to return. By default is 100 and max value could be 1000.
  1620. * 'prefix' => specifies the key prefix the returned objects must have. Note that the returned keys still contain the prefix.
  1621. * 'delimiter' => The delimiter of object name for grouping object. When it's specified, listObjectVersions will differeniate the object and folder. And it will return subfolder's objects.
  1622. * 'key-marker' => The key of returned object must be greater than the 'key-marker'.
  1623. * 'version-id-marker' => The version id of returned object must be greater than the 'version-id-marker'.
  1624. *)
  1625. * Prefix and marker are for filtering and paging. Their length must be less than 256 bytes
  1626. * @return ObjectVersionListInfo|null
  1627. * @throws OssException|RequestCore_Exception
  1628. */
  1629. public function listObjectVersions($bucket, $options = NULL)
  1630. {
  1631. $this->precheckCommon($bucket, NULL, $options, false);
  1632. $options[self::OSS_BUCKET] = $bucket;
  1633. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  1634. $options[self::OSS_SUB_RESOURCE] = 'versions';
  1635. $query = isset($options[self::OSS_QUERY_STRING]) ? $options[self::OSS_QUERY_STRING] : array();
  1636. $options[self::OSS_QUERY_STRING] = array_merge(
  1637. $query,
  1638. array(self::OSS_ENCODING_TYPE => self::OSS_ENCODING_TYPE_URL,
  1639. self::OSS_DELIMITER => isset($options[self::OSS_DELIMITER]) ? $options[self::OSS_DELIMITER] : '/',
  1640. self::OSS_PREFIX => isset($options[self::OSS_PREFIX]) ? $options[self::OSS_PREFIX] : '',
  1641. self::OSS_MAX_KEYS => isset($options[self::OSS_MAX_KEYS]) ? $options[self::OSS_MAX_KEYS] : self::OSS_MAX_KEYS_VALUE,
  1642. self::OSS_KEY_MARKER => isset($options[self::OSS_KEY_MARKER]) ? $options[self::OSS_KEY_MARKER] : '',
  1643. self::OSS_VERSION_ID_MARKER => isset($options[self::OSS_VERSION_ID_MARKER]) ? $options[self::OSS_VERSION_ID_MARKER] : '')
  1644. );
  1645. $response = $this->auth($options);
  1646. $result = new ListObjectVersionsResult($response);
  1647. return $result->getData();
  1648. }
  1649. /**
  1650. * Creates a virtual 'folder' in OSS. The name should not end with '/' because the method will append the name with a '/' anyway.
  1651. *
  1652. * Internal use only.
  1653. *
  1654. * @param string $bucket bucket name
  1655. * @param string $object object name
  1656. * @param array $options
  1657. * @return array|null
  1658. * @throws OssException|RequestCore_Exception
  1659. */
  1660. public function createObjectDir($bucket, $object, $options = NULL)
  1661. {
  1662. $this->precheckCommon($bucket, $object, $options);
  1663. $options[self::OSS_BUCKET] = $bucket;
  1664. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  1665. $options[self::OSS_OBJECT] = $object . '/';
  1666. $options[self::OSS_CONTENT_LENGTH] = array(self::OSS_CONTENT_LENGTH => 0);
  1667. $response = $this->auth($options);
  1668. $result = new PutSetDeleteResult($response);
  1669. return $result->getData();
  1670. }
  1671. /**
  1672. * Uploads the $content object to OSS.
  1673. *
  1674. * @param string $bucket bucket name
  1675. * @param string $object objcet name
  1676. * @param string $content The content object
  1677. * @param array $options
  1678. * @return array|null
  1679. * @throws OssException|RequestCore_Exception
  1680. */
  1681. public function putObject($bucket, $object, $content, $options = NULL)
  1682. {
  1683. $this->precheckCommon($bucket, $object, $options);
  1684. $options[self::OSS_CONTENT] = $content;
  1685. $options[self::OSS_BUCKET] = $bucket;
  1686. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  1687. $options[self::OSS_OBJECT] = $object;
  1688. if (!isset($options[self::OSS_LENGTH])) {
  1689. $options[self::OSS_CONTENT_LENGTH] = strlen($options[self::OSS_CONTENT]);
  1690. } else {
  1691. $options[self::OSS_CONTENT_LENGTH] = $options[self::OSS_LENGTH];
  1692. }
  1693. $is_check_md5 = $this->isCheckMD5($options);
  1694. if ($is_check_md5) {
  1695. $content_md5 = base64_encode(md5($content, true));
  1696. $options[self::OSS_CONTENT_MD5] = $content_md5;
  1697. }
  1698. if (!isset($options[self::OSS_CONTENT_TYPE])) {
  1699. $options[self::OSS_CONTENT_TYPE] = $this->getMimeType($object);
  1700. }
  1701. $response = $this->auth($options);
  1702. if (isset($options[self::OSS_CALLBACK]) && !empty($options[self::OSS_CALLBACK])) {
  1703. $result = new CallbackResult($response);
  1704. } else {
  1705. $result = new PutSetDeleteResult($response);
  1706. }
  1707. return $result->getData();
  1708. }
  1709. /**
  1710. * creates symlink
  1711. * @param string $bucket bucket name
  1712. * @param string $symlink symlink name
  1713. * @param string $targetObject targetObject name
  1714. * @param array $options
  1715. * @return array|null
  1716. * @throws OssException|RequestCore_Exception
  1717. */
  1718. public function putSymlink($bucket, $symlink, $targetObject, $options = NULL)
  1719. {
  1720. $this->precheckCommon($bucket, $symlink, $options);
  1721. $options[self::OSS_BUCKET] = $bucket;
  1722. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  1723. $options[self::OSS_OBJECT] = $symlink;
  1724. $options[self::OSS_SUB_RESOURCE] = self::OSS_SYMLINK;
  1725. $options[self::OSS_HEADERS][self::OSS_SYMLINK_TARGET] = rawurlencode($targetObject);
  1726. $response = $this->auth($options);
  1727. $result = new PutSetDeleteResult($response);
  1728. return $result->getData();
  1729. }
  1730. /**
  1731. * Gets symlink
  1732. * @param string $bucket bucket name
  1733. * @param string $symlink symlink name
  1734. * @param array $options
  1735. * @return array|null
  1736. * @throws OssException|RequestCore_Exception
  1737. */
  1738. public function getSymlink($bucket, $symlink, $options = NULL)
  1739. {
  1740. $this->precheckCommon($bucket, $symlink, $options);
  1741. $options[self::OSS_BUCKET] = $bucket;
  1742. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  1743. $options[self::OSS_OBJECT] = $symlink;
  1744. $options[self::OSS_SUB_RESOURCE] = self::OSS_SYMLINK;
  1745. $response = $this->auth($options);
  1746. $result = new SymlinkResult($response);
  1747. return $result->getData();
  1748. }
  1749. /**
  1750. * Uploads a local file
  1751. *
  1752. * @param string $bucket bucket name
  1753. * @param string $object object name
  1754. * @param string $file local file path
  1755. * @param array $options
  1756. * @return array|null
  1757. * @throws OssException|RequestCore_Exception
  1758. */
  1759. public function uploadFile($bucket, $object, $file, $options = NULL)
  1760. {
  1761. $this->precheckCommon($bucket, $object, $options);
  1762. OssUtil::throwOssExceptionWithMessageIfEmpty($file, "file path is invalid");
  1763. $file = $this->encodeFilePath($file);
  1764. if (!file_exists($file)) {
  1765. throw new OssException($file . " file does not exist");
  1766. }
  1767. $options[self::OSS_FILE_UPLOAD] = $file;
  1768. $file_size = sprintf('%u', filesize($options[self::OSS_FILE_UPLOAD]));
  1769. $is_check_md5 = $this->isCheckMD5($options);
  1770. if ($is_check_md5) {
  1771. $content_md5 = base64_encode(md5_file($options[self::OSS_FILE_UPLOAD], true));
  1772. $options[self::OSS_CONTENT_MD5] = $content_md5;
  1773. }
  1774. if (!isset($options[self::OSS_CONTENT_TYPE])) {
  1775. $options[self::OSS_CONTENT_TYPE] = $this->getMimeType($object, $file);
  1776. }
  1777. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  1778. $options[self::OSS_BUCKET] = $bucket;
  1779. $options[self::OSS_OBJECT] = $object;
  1780. $options[self::OSS_CONTENT_LENGTH] = $file_size;
  1781. $response = $this->auth($options);
  1782. $result = new PutSetDeleteResult($response);
  1783. return $result->getData();
  1784. }
  1785. /**
  1786. * Uploads object from file handle
  1787. *
  1788. * @param string $bucket bucket name
  1789. * @param string $object object name
  1790. * @param resource $handle file handle
  1791. * @param array $options
  1792. * @return array|null
  1793. * @throws OssException|RequestCore_Exception
  1794. */
  1795. public function uploadStream($bucket, $object, $handle, $options = NULL)
  1796. {
  1797. $this->precheckCommon($bucket, $object, $options);
  1798. if (!is_resource($handle)) {
  1799. throw new OssException("The handle must be an opened stream");
  1800. }
  1801. $options[self::OSS_FILE_UPLOAD] = $handle;
  1802. if ($this->isCheckMD5($options)) {
  1803. rewind($handle);
  1804. $ctx = hash_init('md5');
  1805. hash_update_stream($ctx, $handle);
  1806. $content_md5 = base64_encode(hash_final($ctx, true));
  1807. rewind($handle);
  1808. $options[self::OSS_CONTENT_MD5] = $content_md5;
  1809. }
  1810. if (!isset($options[self::OSS_CONTENT_TYPE])) {
  1811. $options[self::OSS_CONTENT_TYPE] = $this->getMimeType($object);
  1812. }
  1813. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  1814. $options[self::OSS_BUCKET] = $bucket;
  1815. $options[self::OSS_OBJECT] = $object;
  1816. if (!isset($options[self::OSS_CONTENT_LENGTH])) {
  1817. $stat = fstat($handle);
  1818. $options[self::OSS_CONTENT_LENGTH] = $stat[self::OSS_SIZE];
  1819. }
  1820. $response = $this->auth($options);
  1821. $result = new PutSetDeleteResult($response);
  1822. return $result->getData();
  1823. }
  1824. /**
  1825. * Append the object with the content at the specified position.
  1826. * The specified position is typically the lengh of the current file.
  1827. * @param string $bucket bucket name
  1828. * @param string $object objcet name
  1829. * @param string $content content to append
  1830. * @param array $options
  1831. * @return int|null next append position
  1832. * @throws OssException|RequestCore_Exception
  1833. */
  1834. public function appendObject($bucket, $object, $content, $position, $options = NULL)
  1835. {
  1836. $this->precheckCommon($bucket, $object, $options);
  1837. $options[self::OSS_CONTENT] = $content;
  1838. $options[self::OSS_BUCKET] = $bucket;
  1839. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  1840. $options[self::OSS_OBJECT] = $object;
  1841. $options[self::OSS_SUB_RESOURCE] = 'append';
  1842. $options[self::OSS_POSITION] = strval($position);
  1843. if (!isset($options[self::OSS_LENGTH])) {
  1844. $options[self::OSS_CONTENT_LENGTH] = strlen($options[self::OSS_CONTENT]);
  1845. } else {
  1846. $options[self::OSS_CONTENT_LENGTH] = $options[self::OSS_LENGTH];
  1847. }
  1848. $is_check_md5 = $this->isCheckMD5($options);
  1849. if ($is_check_md5) {
  1850. $content_md5 = base64_encode(md5($content, true));
  1851. $options[self::OSS_CONTENT_MD5] = $content_md5;
  1852. }
  1853. if (!isset($options[self::OSS_CONTENT_TYPE])) {
  1854. $options[self::OSS_CONTENT_TYPE] = $this->getMimeType($object);
  1855. }
  1856. $response = $this->auth($options);
  1857. $result = new AppendResult($response);
  1858. return $result->getData();
  1859. }
  1860. /**
  1861. * Append the object with a local file
  1862. *
  1863. * @param string $bucket bucket name
  1864. * @param string $object object name
  1865. * @param string $file The local file path to append with
  1866. * @param array $options
  1867. * @return int|null next append position
  1868. * @throws OssException|RequestCore_Exception
  1869. */
  1870. public function appendFile($bucket, $object, $file, $position, $options = NULL)
  1871. {
  1872. $this->precheckCommon($bucket, $object, $options);
  1873. OssUtil::throwOssExceptionWithMessageIfEmpty($file, "file path is invalid");
  1874. $file = $this->encodeFilePath($file);
  1875. if (!file_exists($file)) {
  1876. throw new OssException($file . " file does not exist");
  1877. }
  1878. $options[self::OSS_FILE_UPLOAD] = $file;
  1879. $file_size = sprintf('%u', filesize($options[self::OSS_FILE_UPLOAD]));
  1880. $is_check_md5 = $this->isCheckMD5($options);
  1881. if ($is_check_md5) {
  1882. $content_md5 = base64_encode(md5_file($options[self::OSS_FILE_UPLOAD], true));
  1883. $options[self::OSS_CONTENT_MD5] = $content_md5;
  1884. }
  1885. if (!isset($options[self::OSS_CONTENT_TYPE])) {
  1886. $options[self::OSS_CONTENT_TYPE] = $this->getMimeType($object, $file);
  1887. }
  1888. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  1889. $options[self::OSS_BUCKET] = $bucket;
  1890. $options[self::OSS_OBJECT] = $object;
  1891. $options[self::OSS_CONTENT_LENGTH] = $file_size;
  1892. $options[self::OSS_SUB_RESOURCE] = 'append';
  1893. $options[self::OSS_POSITION] = strval($position);
  1894. $response = $this->auth($options);
  1895. $result = new AppendResult($response);
  1896. return $result->getData();
  1897. }
  1898. /**
  1899. * Copy from an existing OSS object to another OSS object. If the target object exists already, it will be overwritten.
  1900. *
  1901. * @param string $fromBucket Source bucket name
  1902. * @param string $fromObject Source object name
  1903. * @param string $toBucket Target bucket name
  1904. * @param string $toObject Target object name
  1905. * @param array $options
  1906. * @return null
  1907. * @throws OssException|RequestCore_Exception
  1908. */
  1909. public function copyObject($fromBucket, $fromObject, $toBucket, $toObject, $options = NULL)
  1910. {
  1911. $this->precheckCommon($fromBucket, $fromObject, $options);
  1912. $this->precheckCommon($toBucket, $toObject, $options);
  1913. $options[self::OSS_BUCKET] = $toBucket;
  1914. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  1915. $options[self::OSS_OBJECT] = $toObject;
  1916. $param = '/' . $fromBucket . '/' . rawurlencode($fromObject);
  1917. if (isset($options[self::OSS_VERSION_ID])) {
  1918. $param = $param . '?versionId=' . $options[self::OSS_VERSION_ID];
  1919. unset($options[self::OSS_VERSION_ID]);
  1920. }
  1921. $options[self::OSS_HEADERS][self::OSS_OBJECT_COPY_SOURCE] = $param;
  1922. $response = $this->auth($options);
  1923. $result = new CopyObjectResult($response);
  1924. return $result->getData();
  1925. }
  1926. /**
  1927. * Gets Object metadata
  1928. *
  1929. * @param string $bucket bucket name
  1930. * @param string $object object name
  1931. * @param string $options Checks out the SDK document for the detail
  1932. * @return array|null
  1933. * @throws OssException|RequestCore_Exception
  1934. */
  1935. public function getObjectMeta($bucket, $object, $options = NULL)
  1936. {
  1937. $this->precheckCommon($bucket, $object, $options);
  1938. $options[self::OSS_BUCKET] = $bucket;
  1939. $options[self::OSS_METHOD] = self::OSS_HTTP_HEAD;
  1940. $options[self::OSS_OBJECT] = $object;
  1941. $response = $this->auth($options);
  1942. $result = new HeaderResult($response);
  1943. return $result->getData();
  1944. }
  1945. /**
  1946. * Gets the simplified metadata of a object.
  1947. * Simplified metadata includes ETag, Size, LastModified.
  1948. *
  1949. * @param string $bucket bucket name
  1950. * @param string $object object name
  1951. * @param string $options Checks out the SDK document for the detail
  1952. * @return array|null
  1953. * @throws OssException|RequestCore_Exception
  1954. */
  1955. public function getSimplifiedObjectMeta($bucket, $object, $options = NULL)
  1956. {
  1957. $this->precheckCommon($bucket, $object, $options);
  1958. $options[self::OSS_BUCKET] = $bucket;
  1959. $options[self::OSS_METHOD] = self::OSS_HTTP_HEAD;
  1960. $options[self::OSS_OBJECT] = $object;
  1961. $options[self::OSS_SUB_RESOURCE] = 'objectMeta';
  1962. $response = $this->auth($options);
  1963. $result = new HeaderResult($response);
  1964. return $result->getData();
  1965. }
  1966. /**
  1967. * Deletes a object
  1968. *
  1969. * @param string $bucket bucket name
  1970. * @param string $object object name
  1971. * @param array $options
  1972. * @return array|null
  1973. * @throws OssException|RequestCore_Exception
  1974. */
  1975. public function deleteObject($bucket, $object, $options = NULL)
  1976. {
  1977. $this->precheckCommon($bucket, $object, $options);
  1978. $options[self::OSS_BUCKET] = $bucket;
  1979. $options[self::OSS_METHOD] = self::OSS_HTTP_DELETE;
  1980. $options[self::OSS_OBJECT] = $object;
  1981. $response = $this->auth($options);
  1982. $result = new PutSetDeleteResult($response);
  1983. return $result->getData();
  1984. }
  1985. /**
  1986. * Deletes multiple objects in a bucket
  1987. *
  1988. * @param string $bucket bucket name
  1989. * @param array $objects object list
  1990. * @param array $options
  1991. * @return array|null
  1992. * @throws OssException|RequestCore_Exception
  1993. */
  1994. public function deleteObjects($bucket, $objects, $options = null)
  1995. {
  1996. $this->precheckCommon($bucket, NULL, $options, false);
  1997. if (!is_array($objects) || !$objects) {
  1998. throw new OssException('objects must be array');
  1999. }
  2000. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  2001. $options[self::OSS_BUCKET] = $bucket;
  2002. $options[self::OSS_SUB_RESOURCE] = 'delete';
  2003. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  2004. $quiet = 'false';
  2005. if (isset($options['quiet'])) {
  2006. if (is_bool($options['quiet'])) { //Boolean
  2007. $quiet = $options['quiet'] ? 'true' : 'false';
  2008. } elseif (is_string($options['quiet'])) { // string
  2009. $quiet = ($options['quiet'] === 'true') ? 'true' : 'false';
  2010. }
  2011. }
  2012. $xmlBody = OssUtil::createDeleteObjectsXmlBody($objects, $quiet);
  2013. $options[self::OSS_CONTENT] = $xmlBody;
  2014. $response = $this->auth($options);
  2015. $result = new DeleteObjectsResult($response);
  2016. return $result->getData();
  2017. }
  2018. /**
  2019. * Deletes multiple objects with version id in a bucket
  2020. *
  2021. * @param string $bucket bucket name
  2022. * @param array $objects DeleteObjectInfo list
  2023. * @param array $options
  2024. * @return DeletedObjectInfo|null
  2025. * @throws OssException|RequestCore_Exception
  2026. */
  2027. public function deleteObjectVersions($bucket, $objects, $options = null)
  2028. {
  2029. $this->precheckCommon($bucket, NULL, $options, false);
  2030. if (!is_array($objects) || !$objects) {
  2031. throw new OssException('objects must be array');
  2032. }
  2033. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  2034. $options[self::OSS_BUCKET] = $bucket;
  2035. $options[self::OSS_SUB_RESOURCE] = 'delete';
  2036. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  2037. $quiet = 'false';
  2038. if (isset($options['quiet'])) {
  2039. if (is_bool($options['quiet'])) { //Boolean
  2040. $quiet = $options['quiet'] ? 'true' : 'false';
  2041. } elseif (is_string($options['quiet'])) { // string
  2042. $quiet = ($options['quiet'] === 'true') ? 'true' : 'false';
  2043. }
  2044. }
  2045. $xmlBody = OssUtil::createDeleteObjectVersionsXmlBody($objects, $quiet);
  2046. $options[self::OSS_CONTENT] = $xmlBody;
  2047. $response = $this->auth($options);
  2048. $result = new DeleteObjectVersionsResult($response);
  2049. return $result->getData();
  2050. }
  2051. /**
  2052. * Gets Object content
  2053. *
  2054. * @param string $bucket bucket name
  2055. * @param string $object object name
  2056. * @param array $options It must contain ALIOSS::OSS_FILE_DOWNLOAD. And ALIOSS::OSS_RANGE is optional and empty means to download the whole file.
  2057. * @return string|null
  2058. * @throws OssException|RequestCore_Exception
  2059. */
  2060. public function getObject($bucket, $object, $options = NULL)
  2061. {
  2062. $this->precheckCommon($bucket, $object, $options);
  2063. $options[self::OSS_BUCKET] = $bucket;
  2064. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  2065. $options[self::OSS_OBJECT] = $object;
  2066. if (isset($options[self::OSS_LAST_MODIFIED])) {
  2067. $options[self::OSS_HEADERS][self::OSS_IF_MODIFIED_SINCE] = $options[self::OSS_LAST_MODIFIED];
  2068. unset($options[self::OSS_LAST_MODIFIED]);
  2069. }
  2070. if (isset($options[self::OSS_ETAG])) {
  2071. $options[self::OSS_HEADERS][self::OSS_IF_NONE_MATCH] = $options[self::OSS_ETAG];
  2072. unset($options[self::OSS_ETAG]);
  2073. }
  2074. if (isset($options[self::OSS_RANGE])) {
  2075. $range = $options[self::OSS_RANGE];
  2076. $options[self::OSS_HEADERS][self::OSS_RANGE] = "bytes=$range";
  2077. unset($options[self::OSS_RANGE]);
  2078. }
  2079. $response = $this->auth($options);
  2080. $result = new BodyResult($response);
  2081. return $result->getData();
  2082. }
  2083. /**
  2084. * Checks if the object exists
  2085. * It's implemented by getObjectMeta().
  2086. *
  2087. * @param string $bucket bucket name
  2088. * @param string $object object name
  2089. * @param array $options
  2090. * @return bool|null True:object exists; False:object does not exist
  2091. * @throws OssException|RequestCore_Exception|
  2092. */
  2093. public function doesObjectExist($bucket, $object, $options = NULL)
  2094. {
  2095. $this->precheckCommon($bucket, $object, $options);
  2096. $options[self::OSS_BUCKET] = $bucket;
  2097. $options[self::OSS_METHOD] = self::OSS_HTTP_HEAD;
  2098. $options[self::OSS_OBJECT] = $object;
  2099. $response = $this->auth($options);
  2100. $result = new ExistResult($response);
  2101. return $result->getData();
  2102. }
  2103. /**
  2104. * Object reading for Archive type
  2105. * Use Restore to enable the server to perform the thawing task
  2106. *
  2107. * @param string $bucket bucket name
  2108. * @param string $object object name
  2109. * @return array|null
  2110. * @throws OssException|RequestCore_Exception
  2111. */
  2112. public function restoreObject($bucket, $object, $options = NULL)
  2113. {
  2114. $this->precheckCommon($bucket, $object, $options);
  2115. $options[self::OSS_BUCKET] = $bucket;
  2116. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  2117. $options[self::OSS_OBJECT] = $object;
  2118. $options[self::OSS_SUB_RESOURCE] = self::OSS_RESTORE;
  2119. if (isset($options[self::OSS_RESTORE_CONFIG])) {
  2120. $config = $options[self::OSS_RESTORE_CONFIG];
  2121. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  2122. $options[self::OSS_CONTENT] = $config->serializeToXml();
  2123. }
  2124. $response = $this->auth($options);
  2125. $result = new PutSetDeleteResult($response);
  2126. return $result->getData();
  2127. }
  2128. /**
  2129. * Sets the object tagging
  2130. *
  2131. * @param string $bucket bucket name
  2132. * @param string $object object name
  2133. * @param TaggingConfig $taggingConfig
  2134. * @return array|null
  2135. * @throws OssException|RequestCore_Exception
  2136. */
  2137. public function putObjectTagging($bucket, $object, $taggingConfig, $options = NULL)
  2138. {
  2139. $this->precheckCommon($bucket, $object, $options, true);
  2140. $options[self::OSS_BUCKET] = $bucket;
  2141. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  2142. $options[self::OSS_OBJECT] = $object;
  2143. $options[self::OSS_SUB_RESOURCE] = self::OSS_TAGGING;
  2144. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  2145. $options[self::OSS_CONTENT] = $taggingConfig->serializeToXml();
  2146. $response = $this->auth($options);
  2147. $result = new PutSetDeleteResult($response);
  2148. return $result->getData();
  2149. }
  2150. /**
  2151. * Gets the object tagging
  2152. *
  2153. * @param string $bucket
  2154. * @param string $object
  2155. * @return TaggingConfig|null
  2156. * @throws OssException|RequestCore_Exception
  2157. */
  2158. public function getObjectTagging($bucket, $object, $options = NULL)
  2159. {
  2160. $this->precheckCommon($bucket, $object, $options, true);
  2161. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  2162. $options[self::OSS_BUCKET] = $bucket;
  2163. $options[self::OSS_OBJECT] = $object;
  2164. $options[self::OSS_SUB_RESOURCE] = self::OSS_TAGGING;
  2165. $response = $this->auth($options);
  2166. $result = new GetBucketTagsResult($response);
  2167. return $result->getData();
  2168. }
  2169. /**
  2170. * Deletes the object tagging
  2171. *
  2172. * @param string $bucket
  2173. * @param string $object
  2174. * @return null
  2175. * @throws OssException|RequestCore_Exception
  2176. */
  2177. public function deleteObjectTagging($bucket, $object, $options = NULL)
  2178. {
  2179. $this->precheckCommon($bucket, $object, $options, true);
  2180. $options[self::OSS_METHOD] = self::OSS_HTTP_DELETE;
  2181. $options[self::OSS_BUCKET] = $bucket;
  2182. $options[self::OSS_OBJECT] = $object;
  2183. $options[self::OSS_SUB_RESOURCE] = self::OSS_TAGGING;
  2184. $response = $this->auth($options);
  2185. $result = new PutSetDeleteResult($response);
  2186. return $result->getData();
  2187. }
  2188. /**
  2189. * Processes the object
  2190. *
  2191. * @param string $bucket bucket name
  2192. * @param string $object object name
  2193. * @param string $process process script
  2194. * @return string|null process result, json format
  2195. * @throws OssException|RequestCore_Exception|
  2196. */
  2197. public function processObject($bucket, $object, $process, $options = NULL)
  2198. {
  2199. $this->precheckCommon($bucket, $object, $options);
  2200. $options[self::OSS_BUCKET] = $bucket;
  2201. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  2202. $options[self::OSS_OBJECT] = $object;
  2203. $options[self::OSS_SUB_RESOURCE] = 'x-oss-process';
  2204. $options[self::OSS_CONTENT_TYPE] = 'application/octet-stream';
  2205. $options[self::OSS_CONTENT] = 'x-oss-process=' . $process;
  2206. $response = $this->auth($options);
  2207. $result = new BodyResult($response);
  2208. return $result->getData();
  2209. }
  2210. /**
  2211. * Async Process the object
  2212. *
  2213. * @param string $bucket bucket name
  2214. * @param string $object object name
  2215. * @param string $asyncProcess async process script
  2216. * @param null $options
  2217. * @return string|null process result, json format
  2218. * @throws OssException
  2219. * @throws RequestCore_Exception
  2220. */
  2221. public function asyncProcessObject($bucket, $object, $asyncProcess, $options = NULL)
  2222. {
  2223. $this->precheckCommon($bucket, $object, $options);
  2224. $options[self::OSS_BUCKET] = $bucket;
  2225. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  2226. $options[self::OSS_OBJECT] = $object;
  2227. $options[self::OSS_SUB_RESOURCE] = 'x-oss-async-process';
  2228. $options[self::OSS_CONTENT_TYPE] = 'application/octet-stream';
  2229. $options[self::OSS_CONTENT] = 'x-oss-async-process='.$asyncProcess;
  2230. $response = $this->auth($options);
  2231. $result = new BodyResult($response);
  2232. return $result->getData();
  2233. }
  2234. /**
  2235. * Gets the part size according to the preferred part size.
  2236. * If the specified part size is too small or too big, it will return a min part or max part size instead.
  2237. * Otherwise returns the specified part size.
  2238. * @param int $partSize
  2239. * @return int
  2240. */
  2241. private function computePartSize($partSize)
  2242. {
  2243. $partSize = (integer)$partSize;
  2244. if ($partSize <= self::OSS_MIN_PART_SIZE) {
  2245. $partSize = self::OSS_MIN_PART_SIZE;
  2246. } elseif ($partSize > self::OSS_MAX_PART_SIZE) {
  2247. $partSize = self::OSS_MAX_PART_SIZE;
  2248. }
  2249. return $partSize;
  2250. }
  2251. /**
  2252. * Computes the parts count, size and start position according to the file size and the part size.
  2253. * It must be only called by upload_Part().
  2254. *
  2255. * @param integer $file_size File size
  2256. * @param integer $partSize part size. Default is 5MB
  2257. * @return array An array contains key-value pairs--the key is `seekTo`and value is `length`.
  2258. */
  2259. public function generateMultiuploadParts($file_size, $partSize = 5242880)
  2260. {
  2261. $i = 0;
  2262. $size_count = $file_size;
  2263. $values = array();
  2264. $partSize = $this->computePartSize($partSize);
  2265. while ($size_count > 0) {
  2266. $size_count -= $partSize;
  2267. $values[] = array(
  2268. self::OSS_SEEK_TO => ($partSize * $i),
  2269. self::OSS_LENGTH => (($size_count > 0) ? $partSize : ($size_count + $partSize)),
  2270. );
  2271. $i++;
  2272. }
  2273. return $values;
  2274. }
  2275. /**
  2276. * Initialize a multi-part upload
  2277. *
  2278. * @param string $bucket bucket name
  2279. * @param string $object object name
  2280. * @param array $options Key-Value array
  2281. * @return string|null returns upload id
  2282. * @throws OssException|RequestCore_Exception
  2283. */
  2284. public function initiateMultipartUpload($bucket, $object, $options = NULL)
  2285. {
  2286. $this->precheckCommon($bucket, $object, $options);
  2287. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  2288. $options[self::OSS_BUCKET] = $bucket;
  2289. $options[self::OSS_OBJECT] = $object;
  2290. $options[self::OSS_SUB_RESOURCE] = 'uploads';
  2291. $options[self::OSS_CONTENT] = '';
  2292. if (!isset($options[self::OSS_CONTENT_TYPE])) {
  2293. $options[self::OSS_CONTENT_TYPE] = $this->getMimeType($object);
  2294. }
  2295. if (!isset($options[self::OSS_HEADERS])) {
  2296. $options[self::OSS_HEADERS] = array();
  2297. }
  2298. $response = $this->auth($options);
  2299. $result = new InitiateMultipartUploadResult($response);
  2300. return $result->getData();
  2301. }
  2302. /**
  2303. * Upload a part in a multiparts upload.
  2304. *
  2305. * @param string $bucket bucket name
  2306. * @param string $object object name
  2307. * @param string $uploadId
  2308. * @param array $options Key-Value array
  2309. * @return string|null eTag
  2310. * @throws OssException|RequestCore_Exception
  2311. */
  2312. public function uploadPart($bucket, $object, $uploadId, $options = null)
  2313. {
  2314. $this->precheckCommon($bucket, $object, $options);
  2315. $this->precheckParam($options, self::OSS_FILE_UPLOAD, __FUNCTION__);
  2316. $this->precheckParam($options, self::OSS_PART_NUM, __FUNCTION__);
  2317. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  2318. $options[self::OSS_BUCKET] = $bucket;
  2319. $options[self::OSS_OBJECT] = $object;
  2320. $options[self::OSS_UPLOAD_ID] = $uploadId;
  2321. if (isset($options[self::OSS_LENGTH])) {
  2322. $options[self::OSS_CONTENT_LENGTH] = $options[self::OSS_LENGTH];
  2323. }
  2324. $response = $this->auth($options);
  2325. $result = new UploadPartResult($response);
  2326. return $result->getData();
  2327. }
  2328. /**
  2329. * Gets the uploaded parts.
  2330. *
  2331. * @param string $bucket bucket name
  2332. * @param string $object object name
  2333. * @param string $uploadId uploadId
  2334. * @param array $options Key-Value array
  2335. * @return ListPartsInfo|null
  2336. * @throws OssException|RequestCore_Exception
  2337. */
  2338. public function listParts($bucket, $object, $uploadId, $options = null)
  2339. {
  2340. $this->precheckCommon($bucket, $object, $options);
  2341. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  2342. $options[self::OSS_BUCKET] = $bucket;
  2343. $options[self::OSS_OBJECT] = $object;
  2344. $options[self::OSS_UPLOAD_ID] = $uploadId;
  2345. $options[self::OSS_QUERY_STRING] = array();
  2346. foreach (array('max-parts', 'part-number-marker') as $param) {
  2347. if (isset($options[$param])) {
  2348. $options[self::OSS_QUERY_STRING][$param] = $options[$param];
  2349. unset($options[$param]);
  2350. }
  2351. }
  2352. $response = $this->auth($options);
  2353. $result = new ListPartsResult($response);
  2354. return $result->getData();
  2355. }
  2356. /**
  2357. * Abort a multiparts upload
  2358. *
  2359. * @param string $bucket bucket name
  2360. * @param string $object object name
  2361. * @param string $uploadId uploadId
  2362. * @param array $options Key-Value name
  2363. * @return null
  2364. * @throws OssException|RequestCore_Exception
  2365. */
  2366. public function abortMultipartUpload($bucket, $object, $uploadId, $options = NULL)
  2367. {
  2368. $this->precheckCommon($bucket, $object, $options);
  2369. $options[self::OSS_METHOD] = self::OSS_HTTP_DELETE;
  2370. $options[self::OSS_BUCKET] = $bucket;
  2371. $options[self::OSS_OBJECT] = $object;
  2372. $options[self::OSS_UPLOAD_ID] = $uploadId;
  2373. $response = $this->auth($options);
  2374. $result = new PutSetDeleteResult($response);
  2375. return $result->getData();
  2376. }
  2377. /**
  2378. * Completes a multiparts upload, after all parts are uploaded.
  2379. *
  2380. * @param string $bucket bucket name
  2381. * @param string $object object name
  2382. * @param string $uploadId uploadId
  2383. * @param array $listParts array( array("PartNumber"=> int, "ETag"=>string))
  2384. * @param array $options Key-Value array
  2385. * @return null
  2386. * @throws OssException|RequestCore_Exception
  2387. */
  2388. public function completeMultipartUpload($bucket, $object, $uploadId, $listParts, $options = NULL)
  2389. {
  2390. $this->precheckCommon($bucket, $object, $options);
  2391. $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
  2392. $options[self::OSS_BUCKET] = $bucket;
  2393. $options[self::OSS_OBJECT] = $object;
  2394. $options[self::OSS_UPLOAD_ID] = $uploadId;
  2395. $options[self::OSS_CONTENT_TYPE] = 'application/xml';
  2396. if (is_array($listParts)) {
  2397. $options[self::OSS_CONTENT] = OssUtil::createCompleteMultipartUploadXmlBody($listParts);
  2398. } else {
  2399. $options[self::OSS_CONTENT] = "";
  2400. }
  2401. $response = $this->auth($options);
  2402. if (isset($options[self::OSS_CALLBACK]) && !empty($options[self::OSS_CALLBACK])) {
  2403. $result = new CallbackResult($response);
  2404. } else {
  2405. $result = new PutSetDeleteResult($response);
  2406. }
  2407. return $result->getData();
  2408. }
  2409. /**
  2410. * Lists all ongoing multipart upload events, which means all initialized but not completed or aborted multipart uploads.
  2411. *
  2412. * @param string $bucket bucket
  2413. * @param array $options key-value array--expected keys are 'delimiter', 'key-marker', 'max-uploads', 'prefix', 'upload-id-marker'
  2414. * @return ListMultipartUploadInfo|null
  2415. * @throws OssException|RequestCore_Exception
  2416. */
  2417. public function listMultipartUploads($bucket, $options = null)
  2418. {
  2419. $this->precheckCommon($bucket, NULL, $options, false);
  2420. $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
  2421. $options[self::OSS_BUCKET] = $bucket;
  2422. $options[self::OSS_SUB_RESOURCE] = 'uploads';
  2423. foreach (array('delimiter', 'key-marker', 'max-uploads', 'prefix', 'upload-id-marker') as $param) {
  2424. if (isset($options[$param])) {
  2425. $options[self::OSS_QUERY_STRING][$param] = $options[$param];
  2426. unset($options[$param]);
  2427. }
  2428. }
  2429. $query = isset($options[self::OSS_QUERY_STRING]) ? $options[self::OSS_QUERY_STRING] : array();
  2430. $options[self::OSS_QUERY_STRING] = array_merge(
  2431. $query,
  2432. array(self::OSS_ENCODING_TYPE => self::OSS_ENCODING_TYPE_URL)
  2433. );
  2434. $response = $this->auth($options);
  2435. $result = new ListMultipartUploadResult($response);
  2436. return $result->getData();
  2437. }
  2438. /**
  2439. * Copy an existing file as a part
  2440. *
  2441. * @param string $fromBucket source bucket name
  2442. * @param string $fromObject source object name
  2443. * @param string $toBucket target bucket name
  2444. * @param string $toObject target object name
  2445. * @param int $partNumber Part number
  2446. * @param string $uploadId Upload Id
  2447. * @param array $options Key-Value array---it should have 'start' or 'end' key to specify the range of the source object to copy. If it's not specifed, the whole object is copied.
  2448. * @return null
  2449. * @throws OssException|RequestCore_Exception
  2450. */
  2451. public function uploadPartCopy($fromBucket, $fromObject, $toBucket, $toObject, $partNumber, $uploadId, $options = NULL)
  2452. {
  2453. $this->precheckCommon($fromBucket, $fromObject, $options);
  2454. $this->precheckCommon($toBucket, $toObject, $options);
  2455. //If $options['isFullCopy'] is not set, copy from the beginning
  2456. $start_range = "0";
  2457. if (isset($options['start'])) {
  2458. $start_range = $options['start'];
  2459. }
  2460. $end_range = "";
  2461. if (isset($options['end'])) {
  2462. $end_range = $options['end'];
  2463. }
  2464. $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
  2465. $options[self::OSS_BUCKET] = $toBucket;
  2466. $options[self::OSS_OBJECT] = $toObject;
  2467. $options[self::OSS_PART_NUM] = $partNumber;
  2468. $options[self::OSS_UPLOAD_ID] = $uploadId;
  2469. if (!isset($options[self::OSS_HEADERS])) {
  2470. $options[self::OSS_HEADERS] = array();
  2471. }
  2472. $param = '/' . $fromBucket . '/' . rawurlencode($fromObject);
  2473. if (isset($options[self::OSS_VERSION_ID])) {
  2474. $param = $param . '?versionId=' . $options[self::OSS_VERSION_ID];
  2475. unset($options[self::OSS_VERSION_ID]);
  2476. }
  2477. $options[self::OSS_HEADERS][self::OSS_OBJECT_COPY_SOURCE] = $param;
  2478. $options[self::OSS_HEADERS][self::OSS_OBJECT_COPY_SOURCE_RANGE] = "bytes=" . $start_range . "-" . $end_range;
  2479. $response = $this->auth($options);
  2480. $result = new UploadPartResult($response);
  2481. return $result->getData();
  2482. }
  2483. /**
  2484. * A higher level API for uploading a file with multipart upload. It consists of initialization, parts upload and completion.
  2485. *
  2486. * @param string $bucket bucket name
  2487. * @param string $object object name
  2488. * @param string $file The local file to upload
  2489. * @param array $options Key-Value array
  2490. * @return null
  2491. * @throws OssException|RequestCore_Exception
  2492. */
  2493. public function multiuploadFile($bucket, $object, $file, $options = null)
  2494. {
  2495. $this->precheckCommon($bucket, $object, $options);
  2496. if (isset($options[self::OSS_LENGTH])) {
  2497. $options[self::OSS_CONTENT_LENGTH] = $options[self::OSS_LENGTH];
  2498. unset($options[self::OSS_LENGTH]);
  2499. }
  2500. if (empty($file)) {
  2501. throw new OssException("parameter invalid, file is empty");
  2502. }
  2503. $uploadFile = $this->encodeFilePath($file);
  2504. if (!isset($options[self::OSS_CONTENT_TYPE])) {
  2505. $options[self::OSS_CONTENT_TYPE] = $this->getMimeType($object, $uploadFile);
  2506. }
  2507. $upload_position = isset($options[self::OSS_SEEK_TO]) ? (integer)$options[self::OSS_SEEK_TO] : 0;
  2508. if (isset($options[self::OSS_CONTENT_LENGTH])) {
  2509. $upload_file_size = (integer)$options[self::OSS_CONTENT_LENGTH];
  2510. } else {
  2511. $upload_file_size = sprintf('%u', filesize($uploadFile));
  2512. if ($upload_file_size !== false) {
  2513. $upload_file_size -= $upload_position;
  2514. }
  2515. }
  2516. if ($upload_position === false || !isset($upload_file_size) || $upload_file_size === false || $upload_file_size < 0) {
  2517. throw new OssException('The size of `fileUpload` cannot be determined in ' . __FUNCTION__ . '().');
  2518. }
  2519. // Computes the part size and assign it to options.
  2520. if (isset($options[self::OSS_PART_SIZE])) {
  2521. $options[self::OSS_PART_SIZE] = $this->computePartSize($options[self::OSS_PART_SIZE]);
  2522. } else {
  2523. $options[self::OSS_PART_SIZE] = self::OSS_MID_PART_SIZE;
  2524. }
  2525. $is_check_md5 = $this->isCheckMD5($options);
  2526. // if the file size is less than part size, use simple file upload.
  2527. if ($upload_file_size < $options[self::OSS_PART_SIZE] && !isset($options[self::OSS_UPLOAD_ID])) {
  2528. return $this->uploadFile($bucket, $object, $uploadFile, $options);
  2529. }
  2530. // Using multipart upload, initialize if no OSS_UPLOAD_ID is specified in options.
  2531. if (isset($options[self::OSS_UPLOAD_ID])) {
  2532. $uploadId = $options[self::OSS_UPLOAD_ID];
  2533. } else {
  2534. // initialize
  2535. $uploadId = $this->initiateMultipartUpload($bucket, $object, $options);
  2536. }
  2537. // generates the parts information and upload them one by one
  2538. $pieces = $this->generateMultiuploadParts($upload_file_size, (integer)$options[self::OSS_PART_SIZE]);
  2539. $response_upload_part = array();
  2540. foreach ($pieces as $i => $piece) {
  2541. $from_pos = $upload_position + (integer)$piece[self::OSS_SEEK_TO];
  2542. $to_pos = (integer)$piece[self::OSS_LENGTH] + $from_pos - 1;
  2543. $up_options = array(
  2544. self::OSS_FILE_UPLOAD => $uploadFile,
  2545. self::OSS_PART_NUM => ($i + 1),
  2546. self::OSS_SEEK_TO => $from_pos,
  2547. self::OSS_LENGTH => $to_pos - $from_pos + 1,
  2548. self::OSS_CHECK_MD5 => $is_check_md5,
  2549. );
  2550. if ($is_check_md5) {
  2551. $content_md5 = OssUtil::getMd5SumForFile($uploadFile, $from_pos, $to_pos);
  2552. $up_options[self::OSS_CONTENT_MD5] = $content_md5;
  2553. }
  2554. $response_upload_part[] = $this->uploadPart($bucket, $object, $uploadId, $up_options);
  2555. }
  2556. $uploadParts = array();
  2557. foreach ($response_upload_part as $i => $etag) {
  2558. $uploadParts[] = array(
  2559. 'PartNumber' => ($i + 1),
  2560. 'ETag' => $etag,
  2561. );
  2562. }
  2563. //build complete options
  2564. $cmp_options = null;
  2565. if (isset($options[self::OSS_HEADERS]) && isset($options[self::OSS_HEADERS][self::OSS_REQUEST_PAYER])) {
  2566. $cmp_options = array(
  2567. OssClient::OSS_HEADERS => array(
  2568. OssClient::OSS_REQUEST_PAYER => $options[self::OSS_HEADERS][self::OSS_REQUEST_PAYER],
  2569. ));
  2570. }
  2571. return $this->completeMultipartUpload($bucket, $object, $uploadId, $uploadParts, $cmp_options);
  2572. }
  2573. /**
  2574. * Uploads the local directory to the specified bucket into specified folder (prefix)
  2575. *
  2576. * @param string $bucket bucket name
  2577. * @param string $prefix The object key prefix. Typically it's folder name. The name should not end with '/' as the API appends it automatically.
  2578. * @param string $localDirectory The local directory to upload
  2579. * @param string $exclude To excluded directories
  2580. * @param bool $recursive Recursive flag. True: Recursively upload all datas under the local directory; False: only upload first layer's files.
  2581. * @param bool $checkMd5
  2582. * @return array Returns two list: array("succeededList" => array("object"), "failedList" => array("object"=>"errorMessage"))
  2583. * @throws OssException
  2584. */
  2585. public function uploadDir($bucket, $prefix, $localDirectory, $exclude = '.|..|.svn|.git', $recursive = false, $checkMd5 = true)
  2586. {
  2587. $retArray = array("succeededList" => array(), "failedList" => array());
  2588. if (empty($bucket)) throw new OssException("parameter error, bucket is empty");
  2589. if (!is_string($prefix)) throw new OssException("parameter error, prefix is not string");
  2590. if (empty($localDirectory)) throw new OssException("parameter error, localDirectory is empty");
  2591. $directory = $localDirectory;
  2592. $directory = $this->encodeFilePath($directory);
  2593. //If it's not the local directory, throw OSSException.
  2594. if (!is_dir($directory)) {
  2595. throw new OssException('parameter error: ' . $directory . ' is not a directory, please check it');
  2596. }
  2597. //read directory
  2598. $file_list_array = OssUtil::readDir($directory, $exclude, $recursive);
  2599. if (!$file_list_array) {
  2600. throw new OssException($directory . ' is empty...');
  2601. }
  2602. foreach ($file_list_array as $k => $item) {
  2603. if (is_dir($item['path'])) {
  2604. continue;
  2605. }
  2606. $options = array(
  2607. self::OSS_PART_SIZE => self::OSS_MIN_PART_SIZE,
  2608. self::OSS_CHECK_MD5 => $checkMd5,
  2609. );
  2610. //mbstring to utf-8
  2611. $fileName = $this->decodeFilePath($item['file']);
  2612. $realObject = (!empty($prefix) ? $prefix . '/' : '') . $fileName;
  2613. try {
  2614. $this->multiuploadFile($bucket, $realObject, $item['path'], $options);
  2615. $retArray["succeededList"][] = $realObject;
  2616. } catch (OssException $e) {
  2617. $retArray["failedList"][$realObject] = $e->getMessage();
  2618. }
  2619. }
  2620. return $retArray;
  2621. }
  2622. /**
  2623. * Sign URL with specified expiration time in seconds (timeout) and HTTP method.
  2624. * The signed URL could be used to access the object directly.
  2625. *
  2626. * @param string $bucket
  2627. * @param string $object
  2628. * @param int $timeout expiration time in seconds.
  2629. * @param string $method
  2630. * @param array $options Key-Value array
  2631. * @return string
  2632. * @throws OssException
  2633. */
  2634. public function signUrl($bucket, $object, $timeout = 60, $method = self::OSS_HTTP_GET, $options = NULL)
  2635. {
  2636. $expiration = time() + $timeout;
  2637. return $this->generatePresignedUrl($bucket, $object, $expiration, $method, $options);
  2638. }
  2639. /**
  2640. * Sign URL with specified expiration time in seconds and HTTP method.
  2641. * The signed URL could be used to access the object directly.
  2642. *
  2643. * @param string $bucket
  2644. * @param string $object
  2645. * @param int $expiration expiration time of the Url, unix epoch, since 1970.1.1 00.00.00 UTC
  2646. * @param string $method
  2647. * @param array $options Key-Value array
  2648. * @return string
  2649. * @throws OssException
  2650. */
  2651. public function generatePresignedUrl($bucket, $object, $expiration, $method = self::OSS_HTTP_GET, $options = NULL)
  2652. {
  2653. $this->precheckObjectExt($object, $this->enableStrictObjName);
  2654. $this->precheckCommon($bucket, $object, $options);
  2655. $cred = $this->provider->getCredentials();
  2656. //method
  2657. if (self::OSS_HTTP_GET !== $method && self::OSS_HTTP_PUT !== $method) {
  2658. throw new OssException("method is invalid");
  2659. }
  2660. // Should https or http be used?
  2661. $scheme = $this->useSSL ? 'https://' : 'http://';
  2662. // gets the host name. If the host name is public domain or private domain, form a third level domain by prefixing the bucket name on the domain name.
  2663. $hostname = $this->generateHostname($bucket);
  2664. $path = $this->generatePath($bucket, $object);
  2665. $headers = $this->generateHeaders($options, '');
  2666. $query_string = $this->generateQueryString($options);
  2667. $query_string = empty($query_string) ? '' : '?' . $query_string;
  2668. $requestUrl = $scheme . $hostname . $path . $query_string;
  2669. //Creates the request
  2670. $request = new RequestCore($requestUrl);
  2671. $request->set_method($method);
  2672. if (isset($options[self::OSS_CALLBACK])) {
  2673. $headers[self::OSS_CALLBACK] = base64_encode($options[self::OSS_CALLBACK]);
  2674. }
  2675. if (isset($options[self::OSS_CALLBACK_VAR])) {
  2676. $headers[self::OSS_CALLBACK_VAR] = base64_encode($options[self::OSS_CALLBACK_VAR]);
  2677. }
  2678. foreach ($headers as $header_key => $header_value) {
  2679. $header_value = trim($header_value);
  2680. if (empty($header_value)) {
  2681. continue;
  2682. }
  2683. $request->add_header($header_key, $header_value);
  2684. }
  2685. $signingOpt = array(
  2686. 'bucket' => $bucket,
  2687. 'key' => $object,
  2688. 'region' => $this->getRegion(),
  2689. 'product' => $this->getProduct(),
  2690. 'expiration' => $expiration,
  2691. );
  2692. $this->signer->presign($request, $cred, $signingOpt);
  2693. return $request->request_url;
  2694. }
  2695. /**
  2696. * validates options. Create a empty array if it's NULL.
  2697. *
  2698. * @param array $options
  2699. * @throws OssException
  2700. */
  2701. private function precheckOptions(&$options)
  2702. {
  2703. OssUtil::validateOptions($options);
  2704. if (!$options) {
  2705. $options = array();
  2706. }
  2707. }
  2708. /**
  2709. * Validates bucket parameter
  2710. *
  2711. * @param string $bucket
  2712. * @param string $errMsg
  2713. * @throws OssException
  2714. */
  2715. private function precheckBucket($bucket, $errMsg = 'bucket is not allowed empty')
  2716. {
  2717. OssUtil::throwOssExceptionWithMessageIfEmpty($bucket, $errMsg);
  2718. if (!OssUtil::validateBucket($bucket)) {
  2719. throw new OssException('"' . $bucket . '"' . 'bucket name is invalid');
  2720. }
  2721. }
  2722. /**
  2723. * validates object parameter
  2724. *
  2725. * @param string $object
  2726. * @throws OssException
  2727. */
  2728. private function precheckObject($object)
  2729. {
  2730. OssUtil::throwOssExceptionWithMessageIfEmpty($object, "object name is empty");
  2731. if (!OssUtil::validateObject($object)) {
  2732. throw new OssException('"' . $object . '"' . ' object name is invalid');
  2733. }
  2734. }
  2735. /**
  2736. * validates object name start with ? or not
  2737. * @param $object string
  2738. * @param $strict boolean
  2739. * @throws OssException
  2740. */
  2741. private function precheckObjectExt($object, $strict)
  2742. {
  2743. $this->precheckObject($object);
  2744. if ($strict) {
  2745. if (is_string($object) && $object[0] === "?") {
  2746. throw new OssException('"' . $object . '"' . ' object name cannot start with `?`');
  2747. }
  2748. }
  2749. }
  2750. /**
  2751. * Check option restore
  2752. *
  2753. * @param $storage string
  2754. * @throws OssException
  2755. */
  2756. private function precheckStorage($storage)
  2757. {
  2758. if (is_string($storage)) {
  2759. switch ($storage) {
  2760. case self::OSS_STORAGE_ARCHIVE:
  2761. return;
  2762. case self::OSS_STORAGE_IA:
  2763. return;
  2764. case self::OSS_STORAGE_STANDARD:
  2765. return;
  2766. case self::OSS_STORAGE_COLDARCHIVE:
  2767. return;
  2768. default:
  2769. break;
  2770. }
  2771. }
  2772. throw new OssException('storage name is invalid');
  2773. }
  2774. /**
  2775. * Validates bucket,options parameters and optionally validate object parameter.
  2776. *
  2777. * @param string $bucket
  2778. * @param string $object
  2779. * @param array $options
  2780. * @param bool $isCheckObject
  2781. */
  2782. private function precheckCommon($bucket, $object, &$options, $isCheckObject = true)
  2783. {
  2784. if ($isCheckObject) {
  2785. $this->precheckObject($object);
  2786. }
  2787. $this->precheckOptions($options);
  2788. $this->precheckBucket($bucket);
  2789. }
  2790. /**
  2791. * checks parameters
  2792. *
  2793. * @param array $options
  2794. * @param string $param
  2795. * @param string $funcName
  2796. * @throws OssException
  2797. */
  2798. private function precheckParam($options, $param, $funcName)
  2799. {
  2800. if (!isset($options[$param])) {
  2801. throw new OssException('The `' . $param . '` options is required in ' . $funcName . '().');
  2802. }
  2803. }
  2804. /**
  2805. * Checks md5
  2806. *
  2807. * @param array $options
  2808. * @return bool|null
  2809. */
  2810. private function isCheckMD5($options)
  2811. {
  2812. return $this->getValue($options, self::OSS_CHECK_MD5, false, true, true);
  2813. }
  2814. /**
  2815. * Gets value of the specified key from the options
  2816. *
  2817. * @param array $options
  2818. * @param string $key
  2819. * @param string $default
  2820. * @param bool $isCheckEmpty
  2821. * @param bool $isCheckBool
  2822. * @return bool|null
  2823. */
  2824. private function getValue($options, $key, $default = NULL, $isCheckEmpty = false, $isCheckBool = false)
  2825. {
  2826. $value = $default;
  2827. if (isset($options[$key])) {
  2828. if ($isCheckEmpty) {
  2829. if (!empty($options[$key])) {
  2830. $value = $options[$key];
  2831. }
  2832. } else {
  2833. $value = $options[$key];
  2834. }
  2835. unset($options[$key]);
  2836. }
  2837. if ($isCheckBool) {
  2838. if ($value !== true && $value !== false) {
  2839. $value = false;
  2840. }
  2841. }
  2842. return $value;
  2843. }
  2844. /**
  2845. * Gets mimetype
  2846. *
  2847. * @param string $object
  2848. * @return string
  2849. */
  2850. private function getMimeType($object, $file = null)
  2851. {
  2852. if (!is_null($file)) {
  2853. $type = MimeTypes::getMimetype($file);
  2854. if (!is_null($type)) {
  2855. return $type;
  2856. }
  2857. }
  2858. $type = MimeTypes::getMimetype($object);
  2859. if (!is_null($type)) {
  2860. return $type;
  2861. }
  2862. return self::DEFAULT_CONTENT_TYPE;
  2863. }
  2864. /**
  2865. * Validates and executes the request according to OSS API protocol.
  2866. *
  2867. * @param array $options
  2868. * @return ResponseCore|string
  2869. * @throws OssException
  2870. * @throws RequestCore_Exception
  2871. */
  2872. private function auth($options)
  2873. {
  2874. OssUtil::validateOptions($options);
  2875. //Object Encoding
  2876. $this->authPrecheckObjectEncoding($options);
  2877. //Validates ACL
  2878. $this->authPrecheckAcl($options);
  2879. $cred = $this->provider->getCredentials();
  2880. $this->checkCredentials($cred);
  2881. $bucket = isset($options[self::OSS_BUCKET]) ? $options[self::OSS_BUCKET] : '';
  2882. $object = isset($options[self::OSS_OBJECT]) ? $options[self::OSS_OBJECT] : '';
  2883. // Should https or http be used?
  2884. $scheme = $this->useSSL ? 'https://' : 'http://';
  2885. // gets the host name. If the host name is public domain or private domain, form a third level domain by prefixing the bucket name on the domain name.
  2886. $hostname = $this->generateHostname($bucket);
  2887. $path = $this->generatePath($bucket, $object);
  2888. $headers = $this->generateHeaders($options, $hostname);
  2889. $query_string = $this->generateQueryString($options);
  2890. $query_string = empty($query_string) ? '' : '?' . $query_string;
  2891. $requestUrl = $scheme . $hostname . $path . $query_string;
  2892. //Creates the request
  2893. $request = new RequestCore($requestUrl, $this->requestProxy);
  2894. $request->set_useragent($this->generateUserAgent());
  2895. // Streaming uploads
  2896. if (isset($options[self::OSS_FILE_UPLOAD])) {
  2897. if (is_resource($options[self::OSS_FILE_UPLOAD])) {
  2898. $length = null;
  2899. if (isset($options[self::OSS_CONTENT_LENGTH])) {
  2900. $length = $options[self::OSS_CONTENT_LENGTH];
  2901. } elseif (isset($options[self::OSS_SEEK_TO])) {
  2902. $stats = fstat($options[self::OSS_FILE_UPLOAD]);
  2903. if ($stats && $stats[self::OSS_SIZE] >= 0) {
  2904. $length = $stats[self::OSS_SIZE] - (integer)$options[self::OSS_SEEK_TO];
  2905. }
  2906. }
  2907. $request->set_read_stream($options[self::OSS_FILE_UPLOAD], $length);
  2908. } else {
  2909. $request->set_read_file($options[self::OSS_FILE_UPLOAD]);
  2910. $length = $request->read_stream_size;
  2911. if (isset($options[self::OSS_CONTENT_LENGTH])) {
  2912. $length = $options[self::OSS_CONTENT_LENGTH];
  2913. } elseif (isset($options[self::OSS_SEEK_TO]) && isset($length)) {
  2914. $length -= (integer)$options[self::OSS_SEEK_TO];
  2915. }
  2916. $request->set_read_stream_size($length);
  2917. }
  2918. }
  2919. if (isset($options[self::OSS_SEEK_TO])) {
  2920. $request->set_seek_position((integer)$options[self::OSS_SEEK_TO]);
  2921. }
  2922. if (isset($options[self::OSS_FILE_DOWNLOAD])) {
  2923. if (is_resource($options[self::OSS_FILE_DOWNLOAD])) {
  2924. $request->set_write_stream($options[self::OSS_FILE_DOWNLOAD]);
  2925. } else {
  2926. $request->set_write_file($options[self::OSS_FILE_DOWNLOAD]);
  2927. }
  2928. }
  2929. if (isset($options[self::OSS_METHOD])) {
  2930. $request->set_method($options[self::OSS_METHOD]);
  2931. }
  2932. if (isset($options[self::OSS_CONTENT])) {
  2933. $request->set_body($options[self::OSS_CONTENT]);
  2934. if (isset($headers[self::OSS_CONTENT_TYPE]) && $headers[self::OSS_CONTENT_TYPE] === 'application/x-www-form-urlencoded') {
  2935. $headers[self::OSS_CONTENT_TYPE] = 'application/octet-stream';
  2936. }
  2937. $headers[self::OSS_CONTENT_LENGTH] = strlen($options[self::OSS_CONTENT]);
  2938. $headers[self::OSS_CONTENT_MD5] = base64_encode(md5($options[self::OSS_CONTENT], true));
  2939. }
  2940. if (isset($options[self::OSS_CALLBACK])) {
  2941. $headers[self::OSS_CALLBACK] = base64_encode($options[self::OSS_CALLBACK]);
  2942. }
  2943. if (isset($options[self::OSS_CALLBACK_VAR])) {
  2944. $headers[self::OSS_CALLBACK_VAR] = base64_encode($options[self::OSS_CALLBACK_VAR]);
  2945. }
  2946. if (!isset($headers[self::OSS_ACCEPT_ENCODING])) {
  2947. $headers[self::OSS_ACCEPT_ENCODING] = '';
  2948. }
  2949. if (!isset($headers[self::OSS_CONTENT_TYPE])) {
  2950. $headers[self::OSS_CONTENT_TYPE] = self::DEFAULT_CONTENT_TYPE;
  2951. }
  2952. foreach ($headers as $header_key => $header_value) {
  2953. $header_value = trim($header_value);
  2954. if (empty($header_value)) {
  2955. continue;
  2956. }
  2957. $request->add_header($header_key, $header_value);
  2958. }
  2959. // sign request
  2960. $signingOpt = array(
  2961. 'bucket' => $bucket,
  2962. 'key' => $object,
  2963. 'region' => $this->getRegion(),
  2964. 'product' => $this->getProduct(),
  2965. );
  2966. if (isset($options[self::OSS_ADDITIONAL_HEADERS])) {
  2967. $signingOpt['additionalHeaders'] = $options[self::OSS_ADDITIONAL_HEADERS];
  2968. }
  2969. $this->signer->sign($request, $cred, $signingOpt);
  2970. $string_to_sign = isset($signingOpt['string_to_sign']) ? $signingOpt['string_to_sign'] : '';
  2971. if ($this->timeout !== 0) {
  2972. $request->timeout = $this->timeout;
  2973. }
  2974. if ($this->connectTimeout !== 0) {
  2975. $request->connect_timeout = $this->connectTimeout;
  2976. }
  2977. try {
  2978. $request->send_request();
  2979. } catch (RequestCore_Exception $e) {
  2980. throw(new OssException('RequestCoreException: ' . $e->getMessage()));
  2981. }
  2982. $response_header = $request->get_response_header();
  2983. $response_header['oss-request-url'] = $requestUrl;
  2984. $response_header['oss-redirects'] = $this->redirects;
  2985. $response_header['oss-stringtosign'] = $string_to_sign;
  2986. $response_header['oss-requestheaders'] = $request->request_headers;
  2987. $data = new ResponseCore($response_header, $request->get_response_body(), $request->get_response_code());
  2988. //retry if OSS Internal Error
  2989. if ((integer)$request->get_response_code() === 500) {
  2990. if ($this->redirects <= $this->maxRetries) {
  2991. //Sets the sleep time betwen each retry.
  2992. $delay = (integer)(pow(4, $this->redirects) * 100000);
  2993. usleep($delay);
  2994. $this->redirects++;
  2995. $data = $this->auth($options);
  2996. }
  2997. }
  2998. $this->redirects = 0;
  2999. return $data;
  3000. }
  3001. /**
  3002. * Sets the max retry count
  3003. *
  3004. * @param int $maxRetries
  3005. * @return void
  3006. */
  3007. public function setMaxTries($maxRetries = 3)
  3008. {
  3009. $this->maxRetries = $maxRetries;
  3010. }
  3011. /**
  3012. * Gets the max retry count
  3013. *
  3014. * @return int
  3015. */
  3016. public function getMaxRetries()
  3017. {
  3018. return $this->maxRetries;
  3019. }
  3020. /**
  3021. * Enaable/disable STS in the URL. This is to determine the $sts value passed from constructor take effect or not.
  3022. *
  3023. * @param boolean $enable
  3024. */
  3025. public function setSignStsInUrl($enable)
  3026. {
  3027. }
  3028. /**
  3029. * @return boolean
  3030. */
  3031. public function isUseSSL()
  3032. {
  3033. return $this->useSSL;
  3034. }
  3035. /**
  3036. * @param boolean $useSSL
  3037. */
  3038. public function setUseSSL($useSSL)
  3039. {
  3040. $this->useSSL = $useSSL;
  3041. }
  3042. /**
  3043. * Checks the object's encoding. Convert it to UTF8 if it's in GBK or GB2312
  3044. *
  3045. * @param mixed $options parameter
  3046. */
  3047. private function authPrecheckObjectEncoding(&$options)
  3048. {
  3049. if ($this->checkObjectEncoding !== true) {
  3050. return;
  3051. }
  3052. if (!isset($options[self::OSS_OBJECT])) {
  3053. return;
  3054. }
  3055. try {
  3056. $tmp_object = $options[self::OSS_OBJECT];
  3057. $encoding = array('UTF-8','GB2312', 'GBK');
  3058. $encode = mb_detect_encoding($tmp_object, $encoding);
  3059. if ($encode === 'UTF-8' || $encode === false) {
  3060. return;
  3061. }
  3062. $tmp_object = iconv($encode, "UTF-8", $tmp_object);
  3063. if ($tmp_object === false) {
  3064. return;
  3065. }
  3066. $options[self::OSS_OBJECT] = $tmp_object;
  3067. } catch (\Exception $e) {
  3068. //IGNORE
  3069. }
  3070. }
  3071. /**
  3072. * Checks if the ACL is one of the 3 predefined one. Throw OSSException if not.
  3073. *
  3074. * @param $options
  3075. * @throws OssException
  3076. */
  3077. private function authPrecheckAcl($options)
  3078. {
  3079. if (isset($options[self::OSS_HEADERS][self::OSS_ACL]) && !empty($options[self::OSS_HEADERS][self::OSS_ACL])) {
  3080. if (!in_array(strtolower($options[self::OSS_HEADERS][self::OSS_ACL]), self::$OSS_ACL_TYPES)) {
  3081. throw new OssException($options[self::OSS_HEADERS][self::OSS_ACL] . ':' . 'acl is invalid(private,public-read,public-read-write)');
  3082. }
  3083. }
  3084. }
  3085. /**
  3086. * Gets the host name for the current request.
  3087. * It could be either a third level domain (prefixed by bucket name) or second level domain if it's CName or IP
  3088. *
  3089. * @param $bucket
  3090. * @return string The host name without the protocol scheem (e.g. https://)
  3091. */
  3092. private function generateHostname($bucket)
  3093. {
  3094. if ($this->hostType === self::OSS_HOST_TYPE_IP || $this->hostType === self::OSS_HOST_TYPE_PATH_STYLE) {
  3095. $hostname = $this->hostname;
  3096. } elseif ($this->hostType === self::OSS_HOST_TYPE_CNAME) {
  3097. $hostname = $this->hostname;
  3098. } else {
  3099. // Private domain or public domain
  3100. $hostname = ($bucket == '') ? $this->hostname : ($bucket . '.') . $this->hostname;
  3101. }
  3102. return $hostname;
  3103. }
  3104. /**
  3105. * Gets the Uri path in the current request
  3106. *
  3107. * @param $bucket
  3108. * @param $object
  3109. * @return string return the resource uri.
  3110. */
  3111. private function generatePath($bucket, $object)
  3112. {
  3113. $paths = array();
  3114. // +bucket
  3115. if ('' !== $bucket) {
  3116. if ($this->hostType === self::OSS_HOST_TYPE_IP || $this->hostType === self::OSS_HOST_TYPE_PATH_STYLE) {
  3117. $paths[] = $bucket;
  3118. }
  3119. }
  3120. // + object
  3121. if ('' !== $object && '/' !== $object) {
  3122. $paths[] = str_replace(array('%2F'), array('/'), rawurlencode($object));
  3123. }
  3124. return '/' . implode('/', $paths);
  3125. }
  3126. /**
  3127. * generates query string
  3128. *
  3129. * @param mixed $options
  3130. * @return string
  3131. */
  3132. private function generateQueryString($options)
  3133. {
  3134. //query parameters
  3135. $query = array();
  3136. $queryList = array(
  3137. self::OSS_PART_NUM,
  3138. self::OSS_UPLOAD_ID,
  3139. self::OSS_COMP,
  3140. self::OSS_LIVE_CHANNEL_STATUS,
  3141. self::OSS_LIVE_CHANNEL_START_TIME,
  3142. self::OSS_LIVE_CHANNEL_END_TIME,
  3143. self::OSS_PROCESS,
  3144. self::OSS_POSITION,
  3145. self::OSS_SYMLINK,
  3146. self::OSS_RESTORE,
  3147. self::OSS_TAGGING,
  3148. self::OSS_WORM_ID,
  3149. self::OSS_TRAFFIC_LIMIT,
  3150. self::OSS_VERSION_ID,
  3151. self::OSS_CONTINUATION_TOKEN,
  3152. self::OSS_CNAME,
  3153. );
  3154. foreach ($queryList as $item) {
  3155. if (isset($options[$item])) {
  3156. $query[$item] = $options[$item];
  3157. }
  3158. }
  3159. if (isset($options[self::OSS_QUERY_STRING])) {
  3160. $query = array_merge($query, $options[self::OSS_QUERY_STRING]);
  3161. }
  3162. if (isset($options[self::OSS_SUB_RESOURCE])) {
  3163. $query[$options[self::OSS_SUB_RESOURCE]] = '';
  3164. }
  3165. return OssUtil::toQueryString($query);
  3166. }
  3167. /**
  3168. * Initialize headers
  3169. *
  3170. * @param mixed $options
  3171. * @param string $hostname hostname
  3172. * @return array
  3173. */
  3174. private function generateHeaders($options, $hostname)
  3175. {
  3176. $headers = array();
  3177. if (!empty($hostname)) {
  3178. $headers[self::OSS_HOST] = $hostname;
  3179. }
  3180. if (isset($options[self::OSS_CONTENT_TYPE])) {
  3181. $headers[self::OSS_CONTENT_TYPE] = $options[self::OSS_CONTENT_TYPE];
  3182. }
  3183. if (isset($options[self::OSS_DATE])) {
  3184. $headers[self::OSS_DATE] = $options[self::OSS_DATE];
  3185. }
  3186. if (isset($options[self::OSS_CONTENT_MD5])) {
  3187. $headers[self::OSS_CONTENT_MD5] = $options[self::OSS_CONTENT_MD5];
  3188. }
  3189. //Merge HTTP headers
  3190. if (isset($options[self::OSS_HEADERS])) {
  3191. $headers = array_merge($headers, $options[self::OSS_HEADERS]);
  3192. }
  3193. return $headers;
  3194. }
  3195. /**
  3196. * Generates UserAgent
  3197. *
  3198. * @return string
  3199. */
  3200. private function generateUserAgent()
  3201. {
  3202. return self::OSS_NAME . "/" . self::OSS_VERSION . " (" . php_uname('s') . "/" . php_uname('r') . "/" . php_uname('m') . ";" . PHP_VERSION . ")";
  3203. }
  3204. /**
  3205. * Checks endpoint type and returns the endpoint without the protocol schema.
  3206. * Figures out the domain's type (ip, cname or private/public domain).
  3207. *
  3208. * @param string $endpoint
  3209. * @param boolean $isCName
  3210. * @return string The domain name without the protocol schema.
  3211. * @throws OssException
  3212. */
  3213. private function checkEndpoint($endpoint, $isCName)
  3214. {
  3215. $ret_endpoint = null;
  3216. if (strpos($endpoint, 'http://') === 0) {
  3217. $ret_endpoint = substr($endpoint, strlen('http://'));
  3218. } elseif (strpos($endpoint, 'https://') === 0) {
  3219. $ret_endpoint = substr($endpoint, strlen('https://'));
  3220. $this->useSSL = true;
  3221. } else {
  3222. $ret_endpoint = $endpoint;
  3223. }
  3224. $ret_endpoint = OssUtil::getHostPortFromEndpoint($ret_endpoint);
  3225. if ($isCName) {
  3226. $this->hostType = self::OSS_HOST_TYPE_CNAME;
  3227. } elseif (OssUtil::isIPFormat($ret_endpoint)) {
  3228. $this->hostType = self::OSS_HOST_TYPE_IP;
  3229. } else {
  3230. $this->hostType = self::OSS_HOST_TYPE_NORMAL;
  3231. }
  3232. return $ret_endpoint;
  3233. }
  3234. /**
  3235. * @param Credentials $credential
  3236. * @throws OssException
  3237. */
  3238. private function checkCredentials($credential)
  3239. {
  3240. if (empty($credential)) {
  3241. throw new OssException("credentials is empty.");
  3242. }
  3243. if (strlen($credential->getAccessKeyId()) == 0) {
  3244. throw new OssException("access key id is empty");
  3245. }
  3246. if (strlen($credential->getAccessKeySecret()) == 0) {
  3247. throw new OssException("access key secret is empty");
  3248. }
  3249. }
  3250. /**
  3251. * For get Sign Product
  3252. * @return string
  3253. */
  3254. private function getProduct()
  3255. {
  3256. if (!empty($this->cloudBoxId)) {
  3257. return self::OSS_CLOUDBOX_PRODUCT;
  3258. }
  3259. return self::OSS_DEFAULT_PRODUCT;
  3260. }
  3261. /**
  3262. * For get Sign Region
  3263. * @return mixed
  3264. */
  3265. private function getRegion()
  3266. {
  3267. if (!empty($this->cloudBoxId)) {
  3268. return $this->cloudBoxId;
  3269. }
  3270. return $this->region;
  3271. }
  3272. /**
  3273. * Encodes the file path from UTF-8 to GBK.
  3274. *
  3275. * @param $filepath
  3276. * @return string
  3277. */
  3278. private function encodeFilePath($filepath)
  3279. {
  3280. if ($this->filePathCompatible !== true) {
  3281. return $filepath;
  3282. }
  3283. if (empty($filepath)) {
  3284. return $filepath;
  3285. }
  3286. try {
  3287. $encoding = array('UTF-8','GB2312', 'GBK');
  3288. $encode = mb_detect_encoding($filepath, $encoding);
  3289. if ($encode !== 'UTF-8') {
  3290. return $filepath;
  3291. }
  3292. $tmp = iconv($encode, 'GBK', $filepath);
  3293. if ($tmp !== false) {
  3294. $filepath = $tmp;
  3295. }
  3296. } catch (\Exception $e) {
  3297. //IGNORE
  3298. }
  3299. return $filepath;
  3300. }
  3301. /**
  3302. * Decodes the file path from GBK to UTF-8.
  3303. *
  3304. * @param $filepath
  3305. * @return string
  3306. */
  3307. private function decodeFilePath($filepath)
  3308. {
  3309. if ($this->filePathCompatible !== true) {
  3310. return $filepath;
  3311. }
  3312. if (empty($filepath)) {
  3313. return $filepath;
  3314. }
  3315. try {
  3316. $encoding = array('UTF-8','GB2312', 'GBK');
  3317. $encode = mb_detect_encoding($filepath, $encoding);
  3318. if ($encode === 'UTF-8' || $encode === false) {
  3319. return $filepath;
  3320. }
  3321. $tmp = iconv($encode, 'UTF-8', $filepath);
  3322. if ($tmp !== false) {
  3323. $filepath = $tmp;
  3324. }
  3325. } catch (\Exception $e) {
  3326. //IGNORE
  3327. }
  3328. return $filepath;
  3329. }
  3330. /**
  3331. * Check if all dependent extensions are installed correctly.
  3332. * For now only "curl" is needed.
  3333. * @throws OssException
  3334. */
  3335. public static function checkEnv()
  3336. {
  3337. if (function_exists('get_loaded_extensions')) {
  3338. //Test curl extension
  3339. $enabled_extension = array("curl");
  3340. $extensions = get_loaded_extensions();
  3341. if ($extensions) {
  3342. foreach ($enabled_extension as $item) {
  3343. if (!in_array($item, $extensions)) {
  3344. throw new OssException("Extension {" . $item . "} is not installed or not enabled, please check your php env.");
  3345. }
  3346. }
  3347. } else {
  3348. throw new OssException("function get_loaded_extensions not found.");
  3349. }
  3350. } else {
  3351. throw new OssException('Function get_loaded_extensions has been disabled, please check php config.');
  3352. }
  3353. }
  3354. /**
  3355. * Sets the http's timeout (in seconds)
  3356. *
  3357. * @param int $timeout
  3358. */
  3359. public function setTimeout($timeout)
  3360. {
  3361. $this->timeout = $timeout;
  3362. }
  3363. /**
  3364. * Sets the http's connection timeout (in seconds)
  3365. *
  3366. * @param int $connectTimeout
  3367. */
  3368. public function setConnectTimeout($connectTimeout)
  3369. {
  3370. $this->connectTimeout = $connectTimeout;
  3371. }
  3372. // Constants for Life cycle
  3373. const OSS_LIFECYCLE_EXPIRATION = "Expiration";
  3374. const OSS_LIFECYCLE_TIMING_DAYS = "Days";
  3375. const OSS_LIFECYCLE_TIMING_DATE = "Date";
  3376. //OSS Internal constants
  3377. const OSS_BUCKET = 'bucket';
  3378. const OSS_OBJECT = 'object';
  3379. const OSS_HEADERS = OssUtil::OSS_HEADERS;
  3380. const OSS_ADDITIONAL_HEADERS = 'additionalHeaders';
  3381. const OSS_METHOD = 'method';
  3382. const OSS_QUERY = 'query';
  3383. const OSS_BASENAME = 'basename';
  3384. const OSS_MAX_KEYS = 'max-keys';
  3385. const OSS_UPLOAD_ID = 'uploadId';
  3386. const OSS_PART_NUM = 'partNumber';
  3387. const OSS_COMP = 'comp';
  3388. const OSS_LIVE_CHANNEL_STATUS = 'status';
  3389. const OSS_LIVE_CHANNEL_START_TIME = 'startTime';
  3390. const OSS_LIVE_CHANNEL_END_TIME = 'endTime';
  3391. const OSS_POSITION = 'position';
  3392. const OSS_MAX_KEYS_VALUE = 100;
  3393. const OSS_MAX_OBJECT_GROUP_VALUE = OssUtil::OSS_MAX_OBJECT_GROUP_VALUE;
  3394. const OSS_MAX_PART_SIZE = OssUtil::OSS_MAX_PART_SIZE;
  3395. const OSS_MID_PART_SIZE = OssUtil::OSS_MID_PART_SIZE;
  3396. const OSS_MIN_PART_SIZE = OssUtil::OSS_MIN_PART_SIZE;
  3397. const OSS_FILE_SLICE_SIZE = 8192;
  3398. const OSS_PREFIX = 'prefix';
  3399. const OSS_DELIMITER = 'delimiter';
  3400. const OSS_MARKER = 'marker';
  3401. const OSS_FETCH_OWNER = 'fetch-owner';
  3402. const OSS_START_AFTER = 'start-after';
  3403. const OSS_CONTINUATION_TOKEN = 'continuation-token';
  3404. const OSS_ACCEPT_ENCODING = 'Accept-Encoding';
  3405. const OSS_CONTENT_MD5 = 'Content-Md5';
  3406. const OSS_SELF_CONTENT_MD5 = 'x-oss-meta-md5';
  3407. const OSS_CONTENT_TYPE = 'Content-Type';
  3408. const OSS_CONTENT_LENGTH = 'Content-Length';
  3409. const OSS_IF_MODIFIED_SINCE = 'If-Modified-Since';
  3410. const OSS_IF_UNMODIFIED_SINCE = 'If-Unmodified-Since';
  3411. const OSS_IF_MATCH = 'If-Match';
  3412. const OSS_IF_NONE_MATCH = 'If-None-Match';
  3413. const OSS_CACHE_CONTROL = 'Cache-Control';
  3414. const OSS_EXPIRES = 'Expires';
  3415. const OSS_CONTENT_COING = 'Content-Coding';
  3416. const OSS_CONTENT_DISPOSTION = 'Content-Disposition';
  3417. const OSS_RANGE = 'range';
  3418. const OSS_ETAG = 'etag';
  3419. const OSS_LAST_MODIFIED = 'lastmodified';
  3420. const OS_CONTENT_RANGE = 'Content-Range';
  3421. const OSS_CONTENT = OssUtil::OSS_CONTENT;
  3422. const OSS_BODY = 'body';
  3423. const OSS_LENGTH = OssUtil::OSS_LENGTH;
  3424. const OSS_HOST = 'Host';
  3425. const OSS_DATE = 'Date';
  3426. const OSS_AUTHORIZATION = 'Authorization';
  3427. const OSS_FILE_DOWNLOAD = 'fileDownload';
  3428. const OSS_FILE_UPLOAD = 'fileUpload';
  3429. const OSS_PART_SIZE = 'partSize';
  3430. const OSS_SEEK_TO = 'seekTo';
  3431. const OSS_SIZE = 'size';
  3432. const OSS_QUERY_STRING = 'query_string';
  3433. const OSS_SUB_RESOURCE = 'sub_resource';
  3434. const OSS_DEFAULT_PREFIX = 'x-oss-';
  3435. const OSS_CHECK_MD5 = 'checkmd5';
  3436. const OSS_CHECK_OBJECT = 'checkobject';
  3437. const DEFAULT_CONTENT_TYPE = 'application/octet-stream';
  3438. const OSS_SYMLINK_TARGET = 'x-oss-symlink-target';
  3439. const OSS_SYMLINK = 'symlink';
  3440. const OSS_HTTP_CODE = 'http_code';
  3441. const OSS_REQUEST_ID = 'x-oss-request-id';
  3442. const OSS_INFO = 'info';
  3443. const OSS_STORAGE = 'storage';
  3444. const OSS_RESTORE = 'restore';
  3445. const OSS_STORAGE_STANDARD = 'Standard';
  3446. const OSS_STORAGE_IA = 'IA';
  3447. const OSS_STORAGE_ARCHIVE = 'Archive';
  3448. const OSS_STORAGE_COLDARCHIVE = 'ColdArchive';
  3449. const OSS_TAGGING = 'tagging';
  3450. const OSS_WORM_ID = 'wormId';
  3451. const OSS_RESTORE_CONFIG = 'restore-config';
  3452. const OSS_KEY_MARKER = 'key-marker';
  3453. const OSS_VERSION_ID_MARKER = 'version-id-marker';
  3454. const OSS_VERSION_ID = 'versionId';
  3455. const OSS_HEADER_VERSION_ID = 'x-oss-version-id';
  3456. const OSS_CNAME = 'cname';
  3457. //private URLs
  3458. const OSS_URL_ACCESS_KEY_ID = 'OSSAccessKeyId';
  3459. const OSS_URL_EXPIRES = 'Expires';
  3460. const OSS_URL_SIGNATURE = 'Signature';
  3461. //HTTP METHOD
  3462. const OSS_HTTP_GET = 'GET';
  3463. const OSS_HTTP_PUT = 'PUT';
  3464. const OSS_HTTP_HEAD = 'HEAD';
  3465. const OSS_HTTP_POST = 'POST';
  3466. const OSS_HTTP_DELETE = 'DELETE';
  3467. const OSS_HTTP_OPTIONS = 'OPTIONS';
  3468. //Others
  3469. const OSS_ACL = 'x-oss-acl';
  3470. const OSS_OBJECT_ACL = 'x-oss-object-acl';
  3471. const OSS_OBJECT_GROUP = 'x-oss-file-group';
  3472. const OSS_MULTI_PART = 'uploads';
  3473. const OSS_MULTI_DELETE = 'delete';
  3474. const OSS_OBJECT_COPY_SOURCE = 'x-oss-copy-source';
  3475. const OSS_OBJECT_COPY_SOURCE_RANGE = "x-oss-copy-source-range";
  3476. const OSS_PROCESS = "x-oss-process";
  3477. const OSS_CALLBACK = "x-oss-callback";
  3478. const OSS_CALLBACK_VAR = "x-oss-callback-var";
  3479. const OSS_REQUEST_PAYER = "x-oss-request-payer";
  3480. const OSS_TRAFFIC_LIMIT = "x-oss-traffic-limit";
  3481. //Constants for STS SecurityToken
  3482. const OSS_SECURITY_TOKEN = "x-oss-security-token";
  3483. const OSS_ACL_TYPE_PRIVATE = 'private';
  3484. const OSS_ACL_TYPE_PUBLIC_READ = 'public-read';
  3485. const OSS_ACL_TYPE_PUBLIC_READ_WRITE = 'public-read-write';
  3486. const OSS_ENCODING_TYPE = "encoding-type";
  3487. const OSS_ENCODING_TYPE_URL = "url";
  3488. const OSS_LIST_TYPE = "list-type";
  3489. // Domain Types
  3490. const OSS_HOST_TYPE_NORMAL = "normal";//http://bucket.oss-cn-hangzhou.aliyuncs.com/object
  3491. const OSS_HOST_TYPE_IP = "ip"; //http://1.1.1.1/bucket/object
  3492. const OSS_HOST_TYPE_SPECIAL = 'special'; //http://bucket.guizhou.gov/object
  3493. const OSS_HOST_TYPE_CNAME = "cname"; //http://mydomain.com/object
  3494. const OSS_HOST_TYPE_PATH_STYLE = "path-style"; //http://oss-cn-hangzhou.aliyuncs.com/bucket/object
  3495. //OSS ACL array
  3496. static $OSS_ACL_TYPES = array(
  3497. self::OSS_ACL_TYPE_PRIVATE,
  3498. self::OSS_ACL_TYPE_PUBLIC_READ,
  3499. self::OSS_ACL_TYPE_PUBLIC_READ_WRITE
  3500. );
  3501. // OssClient version information
  3502. const OSS_NAME = "aliyun-sdk-php";
  3503. const OSS_VERSION = "2.7.1";
  3504. const OSS_BUILD = "20240228";
  3505. const OSS_AUTHOR = "";
  3506. const OSS_OPTIONS_ORIGIN = 'Origin';
  3507. const OSS_OPTIONS_REQUEST_METHOD = 'Access-Control-Request-Method';
  3508. const OSS_OPTIONS_REQUEST_HEADERS = 'Access-Control-Request-Headers';
  3509. // signatrue version information
  3510. const OSS_SIGNATURE_VERSION_V1 = "v1";
  3511. const OSS_SIGNATURE_VERSION_V4 = "v4";
  3512. const OSS_DEFAULT_PRODUCT = "oss";
  3513. const OSS_CLOUDBOX_PRODUCT = "oss-cloudbox";
  3514. //use ssl flag
  3515. private $useSSL = false;
  3516. private $maxRetries = 3;
  3517. private $redirects = 0;
  3518. // user's domain type. It could be one of the four: OSS_HOST_TYPE_NORMAL, OSS_HOST_TYPE_IP, OSS_HOST_TYPE_SPECIAL, OSS_HOST_TYPE_CNAME
  3519. private $hostType = self::OSS_HOST_TYPE_NORMAL;
  3520. private $requestProxy = null;
  3521. /**
  3522. * @var CredentialsProvider
  3523. */
  3524. private $provider;
  3525. private $hostname;
  3526. private $enableStrictObjName;
  3527. private $timeout = 0;
  3528. private $connectTimeout = 0;
  3529. private $cloudBoxId = null;
  3530. private $region = null;
  3531. /**
  3532. * @var SignerV1|SignerV4
  3533. */
  3534. private $signer;
  3535. private $checkObjectEncoding = false;
  3536. private $filePathCompatible;
  3537. }