diff --git a/src/Qcloud/Cos/BucketStyleListener.php b/src/Qcloud/Cos/BucketStyleListener.php index 50f67f42..62fd5efc 100644 --- a/src/Qcloud/Cos/BucketStyleListener.php +++ b/src/Qcloud/Cos/BucketStyleListener.php @@ -58,7 +58,7 @@ public function onCommandAfterPrepare(Event $event) { // Set the key and bucket on the request $request->getParams()->set('bucket', $bucket)->set('key', $key); - $request->setPath(urldecode($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 c9b291e5..4ec91132 100644 --- a/src/Qcloud/Cos/Client.php +++ b/src/Qcloud/Cos/Client.php @@ -119,14 +119,15 @@ public function upload($bucket, $key, $body, $options = array()) { return $multipartUpload->performUploading(); } public function copy($bucket, $key, $copysource, $options = array()) { + $options = Collection::fromConfig(array_change_key_case($options), array( - 'min_part_size' => MultipartUpload::MIN_PART_SIZE, + 'min_part_size' => Copy::MIN_PART_SIZE, 'params' => $options)); $sourcebucket = explode('-',explode('.',$copysource)[0])[0]; $sourceappid = explode('-',explode('.',$copysource)[0])[1]; $sourceregion = explode('.',$copysource)[2]; $sourcekey = substr(strstr($copysource,'/'),1); - $cosClient = new Client(array('region' => getenv('COS_REGION'), + $cosClient = new Client(array('region' => $sourceregion, 'credentials'=> array( 'appId' => $sourceappid, 'secretId' => $this->secretId, @@ -135,8 +136,9 @@ public function copy($bucket, $key, $copysource, $options = array()) { $rt = $cosClient->headObject(array('Bucket'=>$sourcebucket, 'Key'=>$sourcekey)); $contentlength =$rt['ContentLength']; + if ($contentlength < $options['min_part_size']) { - return $this->UploadPartCopy(array( + return $this->copyObject(array( 'Bucket' => $bucket, 'Key' => $key, 'CopySource' => $copysource, diff --git a/src/Qcloud/Cos/Copy.php b/src/Qcloud/Cos/Copy.php index 9b1c7458..9d5ec455 100644 --- a/src/Qcloud/Cos/Copy.php +++ b/src/Qcloud/Cos/Copy.php @@ -8,7 +8,7 @@ class Copy { /** * const var: part size from 5MB to 5GB, and max parts of 10000 are allowed for each upload. */ - const MIN_PART_SIZE = 5242880; + const MIN_PART_SIZE = 52428800; const MAX_PART_SIZE = 5368709120; const MAX_PARTS = 10000; @@ -27,6 +27,11 @@ public function __construct($client, $contentlength, $source, $minPartSize, $opt } public function performUploading() { + + $commands = array(); + + + $uploadId = $this->initiateMultipartUpload(); $offset = 0; $partNumber = 1; @@ -39,15 +44,21 @@ public function performUploading() { $partSize = $this->size - $offset -1; } //echo ('bytes='.( 'bytes='.((string)$offset).'-'.(string)($offset+$partSize))); - $result = $this->client->UploadPartCopy(array( - 'Bucket' => $this->options['Bucket'], - 'Key' => $this->options['Key'], - 'UploadId' => $uploadId, - 'PartNumber' => $partNumber, - 'CopySource'=> $this->source, - 'CopySourceRange' => 'bytes='.((string)$offset).'-'.(string)($offset+$partSize))); - $part = array('PartNumber' => $partNumber, 'ETag' => $result['ETag']); - array_push($parts, $part); + $commands[] = $this->client->getCommand('UploadPartCopy', array( + 'Bucket' => $this->options['Bucket'], + 'Key' => $this->options['Key'], + 'UploadId' => $uploadId, + 'PartNumber' => $partNumber, + 'CopySource'=> $this->source, + 'CopySourceRange' => 'bytes='.((string)$offset).'-'.(string)($offset+$partSize), + )); +// $result = $this->client->UploadPartCopy(array( +// 'Bucket' => $this->options['Bucket'], +// 'Key' => $this->options['Key'], +// 'UploadId' => $uploadId, +// 'PartNumber' => $partNumber, +// 'CopySource'=> $this->source, +// 'CopySourceRange' => 'bytes='.((string)$offset).'-'.(string)($offset+$partSize))); ++$partNumber; $offset += $partSize; if ($this->size == $offset+1) @@ -55,6 +66,17 @@ public function performUploading() { break; } } + $this->client->execute($commands); + + + $partNumber = 1; + foreach ($commands as $command) { + + $result = $command->getResult(); + $part = array('PartNumber' => $partNumber, 'ETag' => $result['ETag']); + array_push($parts, $part); + $partNumber++; + } return $this->client->completeMultipartUpload(array( 'Bucket' => $this->options['Bucket'],