diff --git a/sample.php b/sample.php index e4f9dc8b..ff9a00dd 100644 --- a/sample.php +++ b/sample.php @@ -18,7 +18,7 @@ #createBucket try { - $result = $cosClient->createBucket(array('Bucket' => 'testbucket')); + $result = $cosClient->createBucket(array('Bucket' => 'testbucket-1252448703')); print_r($result); } catch (\Exception $e) { echo "$e\n"; @@ -27,11 +27,14 @@ #uploadbigfile try { $result = $cosClient->upload( - $bucket='testbucket', - $key = '111.txt', - $body = str_repeat('a', 5* 1024 * 1024)); + $bucket='testbucket-1252448703', + $key = '111.txt', + $body = str_repeat('a', 5* 1024 * 1024), + $options = array( + "ACL"=>'private', + 'CacheControl' => 'private')); print_r($result); - } catch (\Exception $e) { +} catch (\Exception $e) { echo "$e\n"; } diff --git a/src/Guzzle/Http/Url.php b/src/Guzzle/Http/Url.php index 6a4e7724..cd822677 100644 --- a/src/Guzzle/Http/Url.php +++ b/src/Guzzle/Http/Url.php @@ -305,7 +305,6 @@ public function normalizePath() $results[] = $segment; } } - // Combine the normalized parts and add the leading slash if needed $this->path = ($this->path[0] == '/' ? '/' : '') . implode('/', $results); diff --git a/src/Qcloud/Cos/BucketStyleListener.php b/src/Qcloud/Cos/BucketStyleListener.php index 1c4251a1..50f67f42 100644 --- a/src/Qcloud/Cos/BucketStyleListener.php +++ b/src/Qcloud/Cos/BucketStyleListener.php @@ -58,8 +58,7 @@ public function onCommandAfterPrepare(Event $event) { // Set the key and bucket on the request $request->getParams()->set('bucket', $bucket)->set('key', $key); - #echo(str_replace("%2F","/",$request->getPath())); - $request->setPath(str_replace("%2F","/",$request->getPath())); + $request->setPath(urldecode($request->getPath())); // Switch to virtual hosted bucket $request->setHost($bucket. '.' . $request->getHost()); if (!$bucket) { diff --git a/src/Qcloud/Cos/Client.php b/src/Qcloud/Cos/Client.php index d7054963..c9b291e5 100644 --- a/src/Qcloud/Cos/Client.php +++ b/src/Qcloud/Cos/Client.php @@ -95,19 +95,18 @@ public function getObjectUrl($bucket, $key, $expires = null, array $args = array return $expires ? $this->createPresignedUrl($request, $expires) : $request->getUrl(); } - public function upload($bucket, $key, $body, $acl = '', $options = array()) { + public function upload($bucket, $key, $body, $options = array()) { $body = EntityBody::factory($body); $options = Collection::fromConfig(array_change_key_case($options), array( 'min_part_size' => MultipartUpload::MIN_PART_SIZE, - 'params' => array())); - + 'params' => $options)); + print_r($options); if ($body->getSize() < $options['min_part_size']) { // Perform a simple PutObject operation return $this->putObject(array( 'Bucket' => $bucket, 'Key' => $key, 'Body' => $body, - 'ACL' => $acl ) + $options['params']); } @@ -115,15 +114,14 @@ public function upload($bucket, $key, $body, $acl = '', $options = array()) { 'Bucket' => $bucket, 'Key' => $key, 'Body' => $body, - 'ACL' => $acl ) + $options['params']); return $multipartUpload->performUploading(); } - public function copy($bucket, $key, $copysource, $acl = '', $options = array()) { + public function copy($bucket, $key, $copysource, $options = array()) { $options = Collection::fromConfig(array_change_key_case($options), array( 'min_part_size' => MultipartUpload::MIN_PART_SIZE, - 'params' => array())); + 'params' => $options)); $sourcebucket = explode('-',explode('.',$copysource)[0])[0]; $sourceappid = explode('-',explode('.',$copysource)[0])[1]; $sourceregion = explode('.',$copysource)[2]; @@ -142,7 +140,6 @@ public function copy($bucket, $key, $copysource, $acl = '', $options = array()) 'Bucket' => $bucket, 'Key' => $key, 'CopySource' => $copysource, - 'ACL' => $acl ) + $options['params']); } $copy = new Copy($this, $contentlength, $copysource, $options['min_part_size'], array( @@ -150,7 +147,6 @@ public function copy($bucket, $key, $copysource, $acl = '', $options = array()) 'Key' => $key, 'ContentLength' => $contentlength, 'CopySource' => $copysource, - 'ACL' => $acl ) + $options['params']); return $copy->performUploading(); @@ -163,8 +159,8 @@ public static function encodeKey($key) { public static function explodeKey($key) { // Remove a leading slash if one is found - //print_r(explode('/', $key && $key[0] == '/' ? substr($key, 1) : $key)); //return explode('/', $key && $key[0] == '/' ? substr($key, 1) : $key); return $key; + return ltrim($key, "/"); } } diff --git a/src/Qcloud/Cos/Command.php b/src/Qcloud/Cos/Command.php index e6750a9e..cf75d46f 100644 --- a/src/Qcloud/Cos/Command.php +++ b/src/Qcloud/Cos/Command.php @@ -26,10 +26,9 @@ public function createPresignedUrl($expires) protected function process() { parent::process(); - // Set the GetObject URL if using the PutObject operation if ($this->result instanceof Model && $this->getName() == 'PutObject') { - $request = $this->getRequest(); + $request = $this->getRequest();; $this->result->set('ObjectURL', $request->getUrl()); } } diff --git a/src/Qcloud/Cos/Service.php b/src/Qcloud/Cos/Service.php index 6528df2c..8f5aff5c 100644 --- a/src/Qcloud/Cos/Service.php +++ b/src/Qcloud/Cos/Service.php @@ -756,6 +756,10 @@ public static function getService() { 'required' => true, 'type' => 'string', 'location' => 'uri'), + 'CacheControl' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'Cache-Control'), 'ContentDisposition' => array( 'type' => 'string', 'location' => 'header', diff --git a/src/Qcloud/Cos/Signature.php b/src/Qcloud/Cos/Signature.php index af352854..302d860c 100644 --- a/src/Qcloud/Cos/Signature.php +++ b/src/Qcloud/Cos/Signature.php @@ -17,6 +17,7 @@ public function __destruct() { } public function signRequest(RequestInterface $request) { + $signTime = (string)(time() - 60) . ';' . (string)(time() + 3600); $httpString = strtolower($request->getMethod()) . "\n" . urldecode($request->getPath()) . "\n\nhost=" . $request->getHost() . "\n"; diff --git a/src/Qcloud/Cos/Tests/ObjectTest.php b/src/Qcloud/Cos/Tests/ObjectTest.php index 653025dc..328cd722 100644 --- a/src/Qcloud/Cos/Tests/ObjectTest.php +++ b/src/Qcloud/Cos/Tests/ObjectTest.php @@ -13,6 +13,7 @@ protected function setUp() { $this->cosClient = new Client(array('region' => getenv('COS_REGION'), 'credentials'=> array( +# 'appId' => getenv('COS_APPID'), 'secretId' => getenv('COS_KEY'), 'secretKey' => getenv('COS_SECRET')))); }